Converting a hex string to an integer

Peter Koren pkoren at hex.net
Fri Mar 31 04:24:26 CEST 2000


Vijay Baliga wrote:
> 
> How can I convert a hex string like '0xab' to an integer? Here is what
> I found:
> >>> int('43')
> 43
> >>> hex(171)
> '0xab'
> >>> int('0xab')
> Traceback (innermost last):
> File "<stdin>", line 1, in ?
> ValueError: invalid literal for int(): 0xab
> Thanks for any help,
> Vijay
> 


>>> def printint(x):
...     print x
...
>>> printint(0xab)
171
>>>     

Regards,

Peter Koren



More information about the Python-list mailing list