在 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。
|
|
温文尔雅的灌汤包 · python - Intersection ...· 2 年前 · |
|
|
果断的沙滩裤 · 「python提取字符串中的数字」相关问答| ...· 2 年前 · |
|
|
正直的小蝌蚪 · emerg invalid number ...· 2 年前 · |
|
|
想出家的绿茶 · Sqlcmd: 错误: Microsoft ...· 2 年前 · |
|
|
腼腆的人字拖 · printf 打印 unit32_t - ...· 2 年前 · |