这是我收到的字节,我想把byte5 + byte6 + byte7 + byte8转换成ASCII码可读的文本。
s=b'0f0000004e52303947303531363400'字节5~8 ASCII/UNICODE为NR09
请帮帮忙谢谢。
发布于 2013-01-12 19:17:41
bytes.fromhex(s[4*2:8*2].decode("ascii")).decode("ascii")
//'NR09'顺便说一句,如果不使用Python : convert a hex string中的转换,这将会容易得多
在这个问题中,你有:
b'\x0f\x00\x00\x00NR09G05164\x00'所以你可以这样做
c = b'\x0f\x00\x00\x00NR09G05164\x00'
c[4:8].decode("ascii")
//'NR09'发布于 2013-01-12 19:22:54
rc@xxxxx:~$ python
Python 2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> s=b'0f0000004e52303947303531363400'
>>> s.decode("hex")[4:8]
'NR09'https://stackoverflow.com/questions/14292746
复制相似问题