小编Sha*_*rma的帖子

如何将 32 位二进制转换为浮点数

我想在 python 中执行从 32 位二进制到浮点数的 IEEE 754 转换。

我试过这个

import struct

f = int('11000001101011000111101011100001', 2)
print struct.unpack('f', struct.pack('i', f))[0]
Run Code Online (Sandbox Code Playgroud)

但这不适用于带有负符号位的数字。

预期的输出应该是这样的:

bintofloat(11000001101011000111101011100001)
>>> -21.56
Run Code Online (Sandbox Code Playgroud)

python floating-point binary ieee-754

0
推荐指数
1
解决办法
6914
查看次数

标签 统计

binary ×1

floating-point ×1

ieee-754 ×1

python ×1