hex string to hex value
tim
tim.vets at skynet.be
Tue Nov 22 19:17:42 EST 2005
mensanator at aol.com wrote:
>tim wrote:
>
>
>>but then i get :
>>
>> >>> m
>>66
>> >>> n=int(hex(m))
>>Traceback (most recent call last):
>> File "<interactive input>", line 1, in ?
>>ValueError: invalid literal for int(): 0x42
>> >>>
>>
>>what am I missing here ?
>>
>>
>
>Avnit's solution was wrong. When converting a string, you
>must state what base you are converting from.
>
>
>
>>>>int(hex(m),16)
>>>>
>>>>
>66
>
>Fredrik Lundh's solution works if the hex string starts with "0x"
>(which it will when the string is created with the hex function).
>
>
>
aren't you converting from a hex string to a decimal value here?
More information about the Python-list
mailing list