0

我从串行连接中逐行读取数据,并以下列格式获取:

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,但不知道该怎么做。

非常感谢您的帮助 - 提前谢谢。

4

1 回答 1

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]
于 2013-11-07T10:37:34.883 回答