12 字节数组加倍 python
12 bytes array to double python
我正在尝试这样做:
struct.unpack('d', barray[:HALF_BYTES])[0]
其中 barray[:HALF_BYTES]
是一个 12 字节数组
但是我收到了这个错误:
Traceback (most recent call last):
File "random_input_sample_drawer.py", line 19, in <module>
print (struct.unpack('d', barray[:HALF_BYTES])[0])
struct.error: unpack requires a bytes object of length 8
我该如何解决?
您可以使用:
int.from_bytes(barray[:HALF_BYTES], byteorder='big', signed=False)
将这 12 个字节转换为一个整数,如果这就是你想要做的,假设你的 barray 是一个 bytearray() 并且你正在使用 python 3.2 +
我正在尝试这样做:
struct.unpack('d', barray[:HALF_BYTES])[0]
其中 barray[:HALF_BYTES]
是一个 12 字节数组
但是我收到了这个错误:
Traceback (most recent call last):
File "random_input_sample_drawer.py", line 19, in <module>
print (struct.unpack('d', barray[:HALF_BYTES])[0])
struct.error: unpack requires a bytes object of length 8
我该如何解决?
您可以使用:
int.from_bytes(barray[:HALF_BYTES], byteorder='big', signed=False)
将这 12 个字节转换为一个整数,如果这就是你想要做的,假设你的 barray 是一个 bytearray() 并且你正在使用 python 3.2 +