converting hex number contained in a string to an integer

Jarkko Torppa torppa at polykoira.megabaud.fi
Tue Jun 20 06:35:12 EDT 2000


In article <8ing7d$o6r$1 at nnrp2.deja.com>, ejfc at my-deja.com wrote:
>Hello all,
>
>I have a string containing a number. This is an
>hex number. How can I convert this to an integer?
...
>How can I do this? I am sure it is really easy,
>but I am just beginnig with
>Python.

>>> eval('0x32')
50
>>> import string
# Forces base to 16(hex)
>>> string.atoi('32',16)
50
# Guesses base from leading characters
>>> string.atoi('0x32',0)
50

-- 
 Jarkko Torppa                torppa at staff.megabaud.fi
  Megabaud Internet-palvelut



More information about the Python-list mailing list