我正在尝试遍历一个非常大的有符号 24 位小端二进制文件以转换为十进制
这是我目前正在使用的代码
def unpack_24bit(bytes):
return bytes[0] | (bytes[1] << 8) | (bytes[2] << 16)
f=open('1.raw','rb')
#Read in the data as a byte array (8-bit array)
ba = bytearray(f.read())[enter image description here][1]
length = len(ba)
print('N-bytes=',length)
#Since the data is in 24bits, convert three bits at a time to a 24 signed bit
nvals = int(length/3);
print('N-recordings for 24bits (3-byte data)=',nvals)
dat = np.zeros(nvals)
for i in range(0,nvals):
dat[i] = (unpack_24bit(struct.unpack('<bbb', ba[3*i:3+i*3])))
它给出的结果可以在这里看到 [1]:https ://i.stack.imgur.com/FfWPn.png 它不太正确
它应该显示为方波
有什么建议么?