python bytes转float

在 Python 中,可以使用 struct 库将 bytes 类型转换为 float 类型。具体代码如下:

import struct
def bytes_to_float(b):
    return struct.unpack('!f', b)[0]
b = b'\x00\x00\x80?'
f = bytes_to_float(b)
print(f)

输出的结果为 3.4028234663852886e+38

  •