我逐行读取串行连接中的数据,并按以下格式获取:
b'002151BF,FFFF9F86'
b'002151C0,FFFF9F89'
b'002151C1,FFFF9F89'
b'002151C2,FFFF9F86'
b'002151C3,FFFF9F84'
b'002151C4,FFFF9F83'
b'002151C5,FFFF9F81'
b'002151C6,FFFF9F7E'
b'002151C7,FFFF9F79'
b'002151C8,FFFF9F76'
b'002151C9,FFFF9F70'
b'002151CA,FFFF9F69'
b'002151CB,FFFF9F67'
b'002151CC,FFFF9F66'
b'002151CD,FFFF9F66'
b'002151CE,FFFF9F68'
正如您所看到的,它是两个8字节的十六进制数字除以逗号。
如何将其解压缩为十进制数?我看过struct.unpack,但无法弄清楚如何去做。
我们将非常感谢您的帮助 - 请提前。
答案 0 :(得分:0)
3>> [int(x, 16) for x in b'002151BF,FFFF9F86'.split(b',')]
[2183615, 4294942598]
3>> [(int(x, 16) + 0x80000000) % 0x100000000 - 0x80000000 for x in b'002151BF,FFFF9F86'.split(b',')]
[2183615, -24698]