converting hex number contained in a string to an integer
Roland Schlenker
rol9999 at attglobal.net
Tue Jun 20 06:48:57 EDT 2000
More information about the Python-list mailing list
Tue Jun 20 06:48:57 EDT 2000
- Previous message (by thread): converting hex number contained in a string to an integer
- Next message (by thread): converting hex number contained in a string to an integer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
ejfc at my-deja.com wrote: > I have a string containing a number. This is an > hex number. How can I convert this to an integer? > > >>> hexnumber > '32' > >>> 0x32 > 50 > >>> int(0x32) > 50 # this is the result I want to get > >>> hexnumber = '0x' + hexnumber > >>> hexnumber > '0x32' > >>> int(hexnumber) > Traceback (innermost last): > File "<interactive input>", line 1, in ? > ValueError: invalid literal for int(): 0x32 >>> import string >>> string.atoi(hexnumber, 16) 50 Roland Schlenker
- Previous message (by thread): converting hex number contained in a string to an integer
- Next message (by thread): converting hex number contained in a string to an integer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list