Base conversion method or module

Andrew Bennetts andrew-pythonlist at puzzling.org
Tue Dec 9 01:45:20 EST 2003


On Tue, Dec 09, 2003 at 06:35:34AM +0000, Jeff Wagner wrote:
> 
> Ok, I must have misunderstood. I am trying something that doesn't seem to be working.
> 
> If I try to take 01011010 (5A) from binary to hex, here is what I get:
> >>> gmpy.digits(01011010,16)    #this is not correct.
> '0x41208'
> 
> >From binary to decimal doesn't work either.
> >>> gmpy.digits(01011010,10)
> '266760'

In Python, integer literals beginning with '0' are in octal, just as how
literals beginning with '0x' are in hex, so 01011010 really is 266760:

>>> print 01011010
266760

So it looks like gmpy is functioning correctly.

-Andrew.






More information about the Python-list mailing list