converting hex number contained in a string to an integer

Thomas Wouters thomas at xs4all.net
Tue Jun 20 07:28:57 EDT 2000


On Tue, Jun 20, 2000 at 10:35:12AM +0000, Jarkko Torppa wrote:

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

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

Note that in Python 1.6, you can do the above two things like this:

>>> int('0x32',16)
50
>>> int('0x32',0)
50

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list