我正在学习LZW数据压缩,我想存储数字>文件中有255个。数字不应存储为字符串,否则压缩将无效。但是,二进制文件只存储数字< = 255.如何存储大于255的数字,这样当我读回它们时,我会得到原始整数?
lst = [256]
writefile = open("C:/Users/Dhruv/Desktop/write.bin", "wb")
buffer = bytes(lst)
print(buffer)
writefile.write(buffer)
writefile.close()
readfile = open("C:/Users/Dhruv/Desktop/write.bin", "rb")
bin = readfile.read(1)
print(ord(bin))
readfile.close()