Converting 2bit hex representation to integer ?
Madhusudan Singh
spammers-go-here at spam.invalid
Wed Oct 19 12:32:54 EDT 2005
Madhusudan Singh wrote:
> Larry Bates wrote:
>
>> Can you give us an example. I don't know what two bit
>> hex means (takes at least 4 bits to make a hex digit).
>
> Like 64(base 16)=100.
> I am referring to 64 in the above.
>
>>
>> Now I'm going to try to guess:
>>
>> If the data is binary then all you need to do is to
>> use the struct.unpack module to convert to integer.
>
> Doesn't unpack presume that the input is a string ? If so, is it safe to
> convert binary data to string using str() ?
Followup to this :
I just tried :
n=str(x)
print struct.unpack("b",n)
I get (51,)
The corresponding output of binascii.b2a_hex(x) is 33.
And 51_10=33_16. So that checks out. What is the deal with the parenthesis
and the comma ?
More information about the Python-list
mailing list