There are binary files saved 20 One hundred million 2 Bytes Number of numbers , It needs to be read out , Every time 20000 Number mapping , Output the result after fitting .
# -*- coding: utf-8 -*- """ @author: kurrrr """ import struct def main(): data_file = open('run0035.bin', 'rb') data_temp = data_file.read(2) data_short, = struct.unpack('h', data_temp) print(data_short) if __name__ == '__main__': main()
open When combined with b key word
read() Function to read , The parameter is the number of bytes read
Use struct Module unpack() Function to convert binary to decimal , Be careful unpack() Function returns tuple, So we need to use data_short, = struct.unpack(‘h', data_temp)
About struct Module format Details can be found on the official website .
The above is the whole content of this paper , I hope it will be helpful for your study , I also hope that you can support .