python - Convert Bytes to Floating Point Numbers? - Stack Overflow
==> struct
Python struct pack, unpack - JournalDev
official doc: struct — Interpret bytes as packed binary data — Python 3.7.12 documentation
note:
e
(6)
float
2
(4)
Float & Hex (String) Float to Hex String4. For the 'f', 'd' and 'e' conversion codes, the packed representation uses the IEEE 754 binary32, binary64 or binary16 format (for 'f', 'd' or 'e' respectively), regardless of the floating-point format used by the platform.
6. The IEEE 754 binary16 “half precision” type was introduced in the 2008 revision of the IEEE 754 standard. It has a sign bit, a 5-bit exponent and 11-bit precision (with 10 bits explicitly stored), and can represent numbers between approximately 6.1e-05 and 6.5e+04 at full precision. This type is not widely supported by C compilers: on a typical machine, an unsigned short can be used for storage, but not for math operations. See the Wikipedia page on the half-precision floating-point format for more information.
python - Convert numpy array of float32 data type to hex format - Stack Overflow
Hex String to Floatfromhex — Python Reference (The Right Way) 0.1 documentation
"Fake" Hex (Bytes) to Floata hex string in the example below is really just a string of bytes in hexadecimal representation
python - Convert hex to float - Stack Overflow
==> fromhex() is a class specific method ==> the best answer in the example use bytes.fromhex() to get a packed buffer, while float.fromhex() requires a entirely different style of hex string.
Float (or Any) to "Fake" Hexsuggestion: use numpy.ndarray.tobytes() ==> give python bytes and can convert to bytes in hex form by:
result = "0x" for byte in list(datum.tobytes())[::-1]: result += hex(byte)[2:].zfill(2) #byte converts to 2 hex. digits return result



