[Tutor] Hex to Str - still an open issue
Alan Gauld
alan.gauld at freenet.co.uk
Sun Feb 6 09:44:42 CET 2005
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.
More information about the Tutor
mailing list