提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
读取二进制文件
提示:在计算机中存储Bytes往往是更加节省空间的,但是在我们进行读取时需要解码。
filepath='F:/2021.gps'
binfile = open(filepath, 'rb') #打开二进制文件
buf = binfile.read(2)#读取两位
一、Python Bytes to Int
buf = b'\xf1\xff'
print(int.from_bytes(buf, byteorder='big', signed=False))
二、Python Bytes to String
buf = b'\xf1\xff'
buf.decode('utf-8', errors='ignore')
三、Python Bytes to Time
时间戳转化
import time
time0=binfile.read(8)
timeArray = time.localtime(int.from_bytes(time0, byteorder='big', signed=False))
FinalTime = time.strftime("%Y--%m--%d %H:%M:%S", timeArray)
print("time:",FinalTime) # 2013--10--10 23:40:00