Converting a hex string to an integer

Peter Koren pkoren at hex.net
Thu Mar 30 21:24:26 EST 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