读取 32 位浮点二进制数据文件(小端) [英] Reading a 32 bit floating point binary data file (little endian)

查看:34
本文介绍了读取 32 位浮点二进制数据文件(小端)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在python中读取一个包含32位浮点二进制数据的二进制数据文件.我尝试在文件上使用 hexdump,然后在 python 中读取 hexdump.转换回浮点数时的一些值返回 nan.我检查了在组合 hexdump 值时是否犯了错误,但找不到任何错误.这就是我在 shell 中所做的:

hexdump -vc >> output.txt

输出格式为c0 05 e5 3f ... 以此类推

我加入了十六进制:'3fe505c0'

这是正确的方法吗?

解决方案

没有

<预><代码>>>>导入结构>>>struct.unpack('<f', 'xc0x05xe5x3f')(1.7892379760742188,)

I want to read a binary data file that contains 32 bit floating point binary data in python. I tried using hexdump on the file and then reading the hexdump in python. Some of the values when converted back to float returned nan. I checked if I made a mistake in combining the hexdump values but couldn't find any. This is what I did this in shell:

hexdump -vc >> output.txt

The output was of the form c0 05 e5 3f ... and so on

I joined the hex as : '3fe505c0'

Is this the correct way to do this ?

解决方案

No.

>>> import struct
>>> struct.unpack('<f', 'xc0x05xe5x3f')
(1.7892379760742188,)

这篇关于读取 32 位浮点二进制数据文件(小端)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆