Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Decode Float (serialized as double)

Trying to decode a bytes array in Python 3.8 where the sending interface spec states the format is "float (serialized as double)".

Using a sample bytes array received from the interface, this is the result i get

>>> import struct
>>> bytes_arr = b'\xbf\xe9\x99\x99\xa0\x00\x00\x00'
>>> print(struct.unpack('d', bytes_arr))
(3.40792534166e-312,)

The parent application (displaying the same data i am receiving over the interface) states the answer to be -0.8. This is obviously rounded but a different decode.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Where am i going wrong?

>Solution :

Your value is in big-endian format:

>>> print(struct.unpack('>d', bytes_arr))
(-0.800000011920929,)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading