转换二进制文件到在Python ASCII [英] Convert binary files into ascii in Python
问题描述
我有一堆包含以下格式的数据的二进制文件:
I have a bunch of binary files that contain data in the following format:
<$c$c>i\\xffhh\\xffhh\\xffhh\\xffih\\xffhh\\xffhh\\xffhh\\xffhh\\xffhi\\xffii\\xffjj\\xffjj\\xffjj\\xffjk\\xffkk\\xffkk\\xffkl\\xffll\\xffmm\\xffmn\\xffnn\\xffon\\xffno\\xffop\\xffop\\xffpp\\xffqq\\xffrq\\xffrs\\xffst\\xfftt\\xfftt\\xffuv\\xffvu\\xffuv\\xffvv\\xffvw\\xffwx\\xffwx\\xffxy\\xffyy\\xffyz\\xffz{\\xffz{\\xff||\\xff}|\\xff~}\\xff}}\\xff~~\\xff~~\\xff~\\x7f\\xff\\x7f\\x7f\\xff\\x7f\\x7f\\xff\\x7f\\x7f\\xff\\x80\\x80\\xff\\x80\\x81\\xff\\x81\\x80\\xff\\x81\\x81\\xff\\x81\\x82\\xff\\x82\\x82\\xff\\x82\\x82\\xff\\x82\\x83\\xff\\x83\\x83\\xff\\x83\\x83\\xff\\x83\\x84\\xff\\x83\\x84\\xff\\x84\\x85\\xff\\x85\\x85\\xff\\x86\\x85\\xff\\x86\\x87\\xff\\x87\\x87\\xff\\x87\\x87\\xff\\x88\\x87\\xff\\x88\\x89\\xff\\x88\\x89\\xff\\x89\\x8a\\xff\\x89\\x8a\\xff\\x8a\\x8b\\xff\\x8b\\x8b\\xff\\x8b\\x8c\\xff\\x8d\\x8d\\xff\\x8d\\x8d\\xff\\x8e\\x8e\\xff\\x8e\\x8f\\xff\\x8f\\x8f$c$c>
这些都应该是从一个人的时候是走pressure传感器读数,所以我假设他们是数字,但我想将它们转换成ASCII,所以我有一些想法,他们是什么。如何转换呢?什么格式,他们目前在?
These are supposed to be pressure sensor readings from when a person is walking, so I'm assuming that they are numbers, but I want to convert them into ascii so I have some idea what they are. How do I convert them? What format are they currently in?
编辑:链接到文件这里提供(链接)
Link to file provided here (Link)
推荐答案
您不能只是打开一个二进制文件猜格式。你必须得到数据的方式将信息存储为特定pressure传感器读数。
You can not guess the format by just opening up a binary file. You will have to get the information on the way data is stored for that particular pressure sensor readings.
当然,当你知道的格式,很容易读取二进制模式文件,然后从它那里得到的所有有意义的数据。
Of course, when you know the format, it is easy to read the file in binary mode and then get all the meaningful data from it
FILE = open(filename,"rb")
FILE.read(numBytes)
这篇关于转换二进制文件到在Python ASCII的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!