[Tutor] Hex to Str - still an open issue
Liam Clarke
cyresse at gmail.com
Sun Feb 6 19:52:02 CET 2005
Ah, thanks all. I wasn't thinking of base 2 numbers like base 10 -
when you describe it like that, I get i. (100 = 10^2 + 0*10^1 +
0*10^0) I was thinking strictly in terms of a base 10 number described
by flags for each power of 2, which (to me) would logically start from
2^0 and go right.
And yeah, I intend to study computer science as I can, so it's
definitely the maths papers first. I'm working through my little
brother's textbook on matrix algebra at the moment. Ick.
Regards,
Liam Clarke
On Sun, 6 Feb 2005 15:10:42 -0000, Alan Gauld <alan.gauld at freenet.co.uk> wrote:
> > While I jest somewhat, that highlights a serious deficiency in my
> > education that becomes more and more apparent, which is in maths.
>
> Yes, its a sad fact. Good programming beyond basics does require a
> modicum of maths. You can learnn enough to do useful things without
> math, but there reaches a point when math becomes essential. Its
> no coincidence that at university Computing was traditionally
> (up till the late 70's at least) a branch of mathematics.
>
> > But the remainder thing - would this be why we read binary the way
> we do?
> >
> > 4 is 001 (on a continuum of 2^0 to 2^n), but using the above
> approach
> > we get 100.
>
> Not really. The reason we read 4 as 100 is the same reason we
> read 400 as 400 instead of 004 - we traditionally put the most
> significant part tothe left since we (in English at least) read
> from left to right.
>
> 400 = 4x10**2 + 0x10**1 + 0x10**0
>
> 110 = 1x2**2 + 0x2**1 + 0x2**0
>
> But if we convert back again we can generate the number 400
> from the value 400 by the same technique we saw for binary:
>
> 400/10 = 40 rem 0
> 40/10 = 4 rem 0
> 4/10 = 0 rem 4
>
> So reading remainders bottom up we get 400, which is
> the decimal representation of 400! :-)
>
> So the algorithm is identical, we can write a generic
> function to convert a value into a representation if we
> pass in the value and base.
>
> Alan G.
>
>
--
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
More information about the Tutor
mailing list