Hex to int conversion error
John Roth
newsgroups at jhrothjr.com
Mon Oct 27 14:17:40 EST 2003
"Adam Ritter" <temporary_addr at hotmail.com> wrote in message
news:mailman.137.1067269508.702.python-list at python.org...
> When I try to convert an 8 digit hex number to an integer, I get a
> ValueError. Why doesn't it convert back correctly? I have the string
> '0xdeadbeaf' stored in a textbox and I would like it's integer value. I
> would convert it to a long, but I need to pack it to send as a 4 byte
> integer through a socket to a C program. Any ideas?
>
> >>>int(0xdeadbeaf)
> -559038801
> >>>int(hex(int(0xdeadbeaf)) ,16)
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> ValueError: int() literal too large: 0xdeadbeaf
>
> Nick
Please see PEP 237. If the timeline in that PEP is still valid,
the meaning will change in Release 2.4.
John Roth
More information about the Python-list
mailing list