converting hex number contained in a string to an integer

ejfc at my-deja.com ejfc at my-deja.com
Tue Jun 20 06:15:08 EDT 2000


Hello all,

I have a string containing a number. This is an
hex number. How can I convert this to an integer?

For instance:

>>> 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
>>>

How can I do this? I am sure it is really easy,
but I am just beginnig with
Python.

Best Regards.
--
Eduardo Fernandez


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list