Re: Inconsistency in hex()
On Wed, 13 Jul 2005 20:57:54 -0700, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> >>> hex(75) >> '0x4b' >> >>> hex(75*256**4) >> '0x4BL' >> >> 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. 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.) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Inconsistency in hex()
Steven D'Aprano <[EMAIL PROTECTED]> writes: > >>> hex(75) > '0x4b' > >>> hex(75*256**4) > '0x4BL' > > 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. -- http://mail.python.org/mailman/listinfo/python-list
Re: Inconsistency in hex()
[Steven D'Aprano] > > hex() of an int appears to return lowercase hex digits, and hex() of a > > long uppercase. [Terry Reedy] > Already bug-reported and fixed for 2.5 (to use lowercase, I believe). > http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=1224347 Score another victory for the time machine ;-) Raymond -- http://mail.python.org/mailman/listinfo/python-list
Re: Inconsistency in hex()
On Tue, 12 Jul 2005 21:17:07 +1000, Steven D'Aprano <[EMAIL PROTECTED]> wrote: >hex() of an int appears to return lowercase hex digits, and hex() of a >long uppercase. > hex(75) >'0x4b' hex(75*256**4) >'0x4BL' > >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. > >>> '%010X'% 0x12345678 '0012345678' >>> '%010X'% 75 '4B' >>> '%010X'% (75*256**4) '4B' >>> '%010X'% (-75*256**4) '-4B' >>> '%010X'% (-75) '-0004B' 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 >>> '%010X'% (-75 &0xff) 'B5' >>> '%010X'% (-75*256**4 &0xff) 'B5' or a helper or a str subclass that does __mod__ differently but that's not with the batteries ;-/ Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: Inconsistency in hex()
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > hex() of an int appears to return lowercase hex digits, and hex() of a > long uppercase. Already bug-reported and fixed for 2.5 (to use lowercase, I believe). http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=1224347 -- http://mail.python.org/mailman/listinfo/python-list
Re: Inconsistency in hex()
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) > '0x4BL' > > 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. >>> def hex(x): ..."""Return the hexadecimal representation of an integer.""" ...return __builtins__.hex(x).upper().rstrip('L') ... >>> hex(75) '0X4B' >>> hex(75 * 256**4) '0X4B' -- http://mail.python.org/mailman/listinfo/python-list
Re: Inconsistency in hex()
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) > '0x4BL' > > 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) 0x4b 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) 1001011 1010210110021101212101010 1023 20234201333002300 403551524040520 32162332321446 045400 <-- base 8 starts with leading 0 1123407355333 322122547200 11467a864463 5251a233140 244b718a01c 1183b2a2b96 85a4947a50 0x4b <-- base 16 starts with leading 0x 2c304c17g7 1b42e32gac ii6ie79hd cbd35i800 8ahh6hjk6 5j31lfeje 42dma7a93 2m5e7gl80 22ja8i0d0 1e2je99kc 13lc7ana3 noclhnpk ijflp0nb elq24la0 blth91bl 9c00 7idw8no3 64hn2ago 5083wbdk 43zbg45c > > It would also be nice if that trailing L would disappear. > > -- > Steven. -- http://mail.python.org/mailman/listinfo/python-list
Inconsistency in hex()
hex() of an int appears to return lowercase hex digits, and hex() of a long uppercase. >>> hex(75) '0x4b' >>> hex(75*256**4) '0x4BL' 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. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list