[Tutor] Hex to Str - still an open issue

Liam Clarke cyresse at gmail.com
Sun Feb 6 09:59:32 CET 2005

Ah, yeah, gotta get me one of those textbooks.
(Wait a minute, that would mean, my approach wasn't the textbook
approach... /me salvages a little pride.)

While I jest somewhat, that highlights a serious deficiency in my
education that becomes more and more apparent, which is in maths.
Sheesh, if I'd known I wanted to use maths for something I enjoyed, I
would've paid attention in class.

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.


Liam Clarke

On Sun, 6 Feb 2005 08:44:42 -0000, Alan Gauld <alan.gauld at freenet.co.uk> wrote:
> Liam,
> > Just looking at this -
> > i = 456
> > s = ''
> > while i:
> >     s = str(i % 2) + s
> >     i/=2
> >
> > This works, far simpler than mine, which is always infuriating, but
> my
> > question is, how exactly?
> This is the classic math treatment of how to calculate a binary
> number.
> Just keep dividing by two and take the remainder into the number.
> Almost any math textbook will cover this approach.
> The snag is that from a computing point of view its pretty slow so
> computer texts usually highlught a lookup approach 8instead.
> 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