Python 二进制读文件 转换 float 失败
資深大佬 : woshichuanqilz 2
python 代码
sacfile = 'binfile' f = open(sacfile, 'rb') hdrBin = f.read()[:4] print(hdrBin) sfmt = 'f' hdrFmt = struct.Struct(sfmt) m_header = hdrFmt.unpack(hdrBin)
输出结果
b'<xa3xd7n’
但是我用 winhex 查看源文件 第一位是 3C 被转换成 ‘<‘ 了 winhex 前八个字节的数据
3CA3D70AC7572000
问题是我需要把前四个 byte 转换为 float 数据, 就是”m_header”
我拿到的结果是错的: 2.0765148849577988e-32
正确的结果应该是: 0.02000000 这个问题怎么解决?
binfile 在这里
https://gitee.com/lovelife_lizhe/ori_data/raw/master/binfile
大佬有話說 (4)