Reading hex to double-precision float python -
i trying unpack
hex string double in python.
when try unpack following:
unpack('d', "4081637ef7d0424a");
i following error:
struct.error: unpack requires string argument of length 8
this doesn't make sense me because double 8 bytes long, and
2 character = 1 hex value = 1 byte
so in essence, double of 8 bytes long 16 character hex string.
any pointers of unpacking hex double super appreciated.
you need convert hex digits binary string first:
struct.unpack('d', "4081637ef7d0424a".decode("hex"))
or
struct.unpack('d', binascii.unhexlify("4081637ef7d0424a"))
the latter version works in both python 2 , 3, former in python 2
Comments
Post a Comment