Converting a hex string to a number
me
here at I.am.me
Tue Jul 9 11:10:03 EDT 2002
Yigal Duppen <yduppen at xs4all.nl> wrote:
>> I am trying to convert a hex string (for example: "0x12345678") to a
>> number (0x12345678 or just 12345678).
YD# You can use int(), with 16 as the value for the second argument (radix)
>>>> int("0x1A2B", 16)
YD# 6699
YD# Of course, if the number is very large, this won't work. In this case,
YD# use long
>>>> int("0x123456789ABCDEF", 16)
YD# Traceback (most recent call last):
YD# File "<stdin>", line 1, in ?
YD# ValueError: int() literal too large: 0x123456789ABCDEF
>>>> long("0x123456789ABCDEF", 16)
YD# 81985529216486895L
YD# YDD
YD# --
YD# .sigmentation Fault
Like this solution. Is there a way to use that long as hex, so bit
operations can be done on it piecewise? Slice a byte, then xor it or
and it, and put it back?
thanks,
stan
More information about the Python-list
mailing list