Hex to int conversion error

Adam Ritter temporary_addr at hotmail.com
Mon Oct 27 10:45:03 EST 2003


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

_________________________________________________________________
Enjoy MSN 8 patented spam control and more with MSN 8 Dial-up Internet 
Service.  Try it FREE for one month!   http://join.msn.com/?page=dept/dialup






More information about the Python-list mailing list