Converting a hex string to a number

Alex Martelli aleax at aleax.it
Tue Jul 9 08:51:11 EDT 2002


tal wrote:

> Hello,
>  I am trying to convert a hex string (for example: "0x12345678") to a
> number (0x12345678 or just 12345678).
>  Can you help me please?
> Thanks, Tal.

>>> s = '0x12345678'
>>> int(s, 0)
305419896

To get 12345678 instead, you'll have to use int(s[2:]) ... :-)


Alex




More information about the Python-list mailing list