如何将little endian float二进制转换为时间格式
How to convert little endian float binary to time format
我正在尝试读取以小端二进制格式编写的 (.SKD) 文件。我确实打开了文件和 select/print 表示时间戳的 4 个字节,我有兴趣将其转换为 HH:MM
的形式
我拥有的字节示例:
26, 231, 215, 85
148, 20, 216, 85
90, 253, 215, 85
试试这个:
import struct
import datetime
def convert(timestamp):
return datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
def binary_to_int(b):
return struct.unpack('<i', b)[0] # read string as little endian integer
sampledata = [26, 231, 215, 85]
binarydata = struct.pack('<BBBB', *sampledata)
timestamp = binary_to_int(binarydata)
result = convert(timestamp)
struct 模块用于将二进制读取为小端
我正在尝试读取以小端二进制格式编写的 (.SKD) 文件。我确实打开了文件和 select/print 表示时间戳的 4 个字节,我有兴趣将其转换为 HH:MM
的形式我拥有的字节示例: 26, 231, 215, 85 148, 20, 216, 85 90, 253, 215, 85
试试这个:
import struct
import datetime
def convert(timestamp):
return datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
def binary_to_int(b):
return struct.unpack('<i', b)[0] # read string as little endian integer
sampledata = [26, 231, 215, 85]
binarydata = struct.pack('<BBBB', *sampledata)
timestamp = binary_to_int(binarydata)
result = convert(timestamp)
struct 模块用于将二进制读取为小端