Inconsistency in hex()

S

Steven D'Aprano

hex() of an int appears to return lowercase hex digits, and hex() of a
long uppercase.
'0x4B00000000L'

By accident or design? Apart from the aesthetic value that lowercase hex
digits are ugly, should we care?

It would also be nice if that trailing L would disappear.
 
M

mensanator

Steven said:
hex() of an int appears to return lowercase hex digits, and hex() of a
long uppercase.

'0x4B00000000L'

By accident or design? Apart from the aesthetic value that lowercase hex
digits are ugly, should we care?

No, just use GMPY.
0x4b00000000

Although it would have been nice to also get rid of the octal
hex prefix inconsistencies.
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
 
D

Dan Bishop

Steven said:
hex() of an int appears to return lowercase hex digits, and hex() of a
long uppercase.

'0x4B00000000L'

By accident or design? Apart from the aesthetic value that lowercase hex
digits are ugly, should we care?

It would also be nice if that trailing L would disappear.

Yes, but that can easily be worked around.
.... """Return the hexadecimal representation of an integer."""
.... return __builtins__.hex(x).upper().rstrip('L')
....'0X4B00000000'
 
B

Bengt Richter

hex() of an int appears to return lowercase hex digits, and hex() of a
long uppercase.

'0x4B00000000L'

By accident or design? Apart from the aesthetic value that lowercase hex
digits are ugly, should we care?

It would also be nice if that trailing L would disappear.
'-00000004B'

I've ranted about the lack of a natural format for showing
the hex of a canonical twos-complement representation of a negative number,
but I guess I'll let it go with this mention ;-)

BTW, yeah, I know it's not so hard to write 'B500000000'
or a helper or a str subclass that does __mod__ differently but that's not with the batteries ;-/
Regards,
Bengt Richter
 
P

Paul Rubin

Steven D'Aprano said:
'0x4B00000000L'

By accident or design? Apart from the aesthetic value that lowercase hex
digits are ugly, should we care?

Use ('%x' % 75) or ('%X' % 75) if you care.
 
S

Steven D'Aprano

Use ('%x' % 75) or ('%X' % 75) if you care.


Ah! Now that's the sort of utterly obvious in hindsight thing that
wouldn't have occurred to me in a month of Sundays. That's why c.l.p is so
useful -- lots of people with lots of ways of doing things, all sharing.

Thanks Paul.

(Actually, I don't care at the moment, but when I do, I'll have a fix.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,261
Messages
2,571,308
Members
47,976
Latest member
AlanaKeech

Latest Threads

Top