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

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -