Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要将二进制数据转换为 ASCII 字符串。该字符串被打包为 15 个字节。为了解析数据包中的其他数据,我使用bitstringPython 模块。但我找不到用于 ASCII 字符串解包的函数。
bitstring
我得到二进制格式的字符串数据:
>> value = const_bit_stream.read(8*15) >> str(value) '0x383638323034303031353732383939'
如何使用bitstring或其他工具将这些字节转换为 ASCII 字符串?
使用 binascii 将二进制转换为 ASCII。
binascii.b2a_uu(data)
其中data是长度为 45 个或更少字符的变量。返回值是转换后的值。
http://docs.python.org/2/library/binascii.html