string.atoi() doesn't do negative base16 - why??
Robert Cragie
rcc at nospamthanks_jennic.com
Mon Jun 12 10:28:15 EDT 2000
Steven Adams <adams_s at lab.eng.usyd.edu.au> wrote in message
news:8i2c9l$b0r$1 at news1.wire.net.au...
| Hi,
|
| my quick hack for going back and forth between binary and base 10, 16 is
| backfiring a bit..
|
| I can form the values as a string, BUT, string.atoi() can't convert
negative
| base hexadecimal strings to integers.
|
| does that make sense?
| e.g
| >>> import string
| >>> hex(-20)
| '0xffffffec'
| >>> string.atoi('0xffffffec',16)
| Traceback (innermost last):
| File "<pyshell#28>", line 1, in ?
| string.atoi('0xffffffec',16)
| ValueError: atoi() literal too large: 0xffffffec
Try
string.atoi('0xffffffec',0)
Yes, I know it's inconsistent :-)
| why is this?
Don't know - I've had lots of fun and games with this.
Robert Cragie
More information about the Python-list
mailing list