這個轉了十進位制又轉了十六進位制,都是string,而不是數值print出來,是以string 輸出的。分享一個我以前的#比如hex.log 裡面是E3F2A1#就要往檔案out.bin裡寫 0xE3 0xF2 0xA1import stringHEX_file_name = "hex.log"BIN_file_name = "out.bin"input_file = open(HEX_file_name,"r")output_file = open(BIN_file_name,"wb")for lines in input_file.readlines():lines = lines.replace(" ","").replace("\n","").upper()for i in range(0, len(lines), 2):chars = lines[i:i+2]output_file.write(chr(int(chars, 16)))input_file.close()output_file.close()核心就是for i in range(0, len(lines), 2):chars = lines[i:i+2]output_file.write(chr(int(chars, 16)))看懂了就懂了out.bin可以用ultraedit或者notepad++十六進位制檢視
這個轉了十進位制又轉了十六進位制,都是string,而不是數值print出來,是以string 輸出的。分享一個我以前的#比如hex.log 裡面是E3F2A1#就要往檔案out.bin裡寫 0xE3 0xF2 0xA1import stringHEX_file_name = "hex.log"BIN_file_name = "out.bin"input_file = open(HEX_file_name,"r")output_file = open(BIN_file_name,"wb")for lines in input_file.readlines():lines = lines.replace(" ","").replace("\n","").upper()for i in range(0, len(lines), 2):chars = lines[i:i+2]output_file.write(chr(int(chars, 16)))input_file.close()output_file.close()核心就是for i in range(0, len(lines), 2):chars = lines[i:i+2]output_file.write(chr(int(chars, 16)))看懂了就懂了out.bin可以用ultraedit或者notepad++十六進位制檢視