hex string to hex value

mensanator at aol.com mensanator at aol.com
Wed Nov 23 00:33:26 CET 2005


avnit wrote:
> If you just want to convert a string to an integer, it would be:
>
> >>> int(n)

That's what the OP tried and it didn't work.

BECAUSE you have to tell the int function what base the string is in
(even though it has "0x" at the start).

>>> int(n,16)
66

>
> in your case it would be:
>
> >>> m=66
> >>> n=int(hex(m))

Wrong again, you still have to tell it what base.

>>> h=int(hex(m),16)
>>> h
66




More information about the Python-list mailing list