Python uses the unpack function of the strike module to decode double floating point numbers

37 views Asked by At

I am using unpack to parse a piece of data, this is a byte stream in it (\x31\x2e\x91\x5a\x8a\x20\xbd\x3e),this corresponds to the double floating-point number in the figure below,I unpack according to type "d",but the result is too small(1.736111111111111e-06). According to the decoded picture, the data should be the number of days since 12/30/1899 or the number of days since the data was collected, which should not be so small. I guess it's code usage. I should have looked for a lot of information, but I couldn't find a way. If anyone can help, I would appreciate it.

decode

These are examples of my code, where I extract the absolute time portion of the data separately and decode it.

import struct
data1 = b'\x31\x2e\x91\x5a\x8a\x20\xbd\x3e'
data2 = b"\x21\x74\x0b\xe7\x06\x6b\xc3\x3e"

decoded_data1 = struct.unpack("d",data1)[0]
decoded_data2 = struct.unpack("d",data2)[0]
print(decoded_data1)
print(decoded_data2)

The result:

1.736111111111111e-06
2.3148148148148148e-06
0

There are 0 answers