Inconsistency in hex()

mensanator at aol.com mensanator at aol.com
Tue Jul 12 12:44:11 EDT 2005



Steven D'Aprano wrote:
> hex() of an int appears to return lowercase hex digits, and hex() of a
> long uppercase.
>
> >>> hex(75)
> '0x4b'
> >>> hex(75*256**4)
> '0x4B00000000L'
>
> By accident or design? Apart from the aesthetic value that lowercase hex
> digits are ugly, should we care?

No, just use GMPY.

>>> from gmpy import *
>>> print digits(75,16)
0x4b
>>> print digits(75*256**4,16)
0x4b00000000

Although it would have been nice to also get rid of the octal
hex prefix inconsistencies.

>>> for b in range(2,37):
	print digits(75*256**4,b)

100101100000000000000000000000000000000
1010210110021101212101010
10230000000000000000
20234201333002300
403551524040520
32162332321446
04540000000000         <-- base 8 starts with leading 0
1123407355333
322122547200
11467a864463
5251a233140
244b718a01c
1183b2a2b96
85a4947a50
0x4b00000000           <-- base 16 starts with leading 0x
2c304c17g7
1b42e32gac
ii6ie79hd
cbd35i800
8ahh6hjk6
5j31lfeje
42dma7a93
2m5e7gl80
22ja8i0d0
1e2je99kc
13lc7ana3
noclhnpk
ijflp0nb
elq24la0
blth91bl
9c000000
7idw8no3
64hn2ago
5083wbdk
43zbg45c



>
> It would also be nice if that trailing L would disappear.
> 
> -- 
> Steven.




More information about the Python-list mailing list