將16進(jìn)制的字符串轉(zhuǎn)成字符串 python16進(jìn)制字符串轉(zhuǎn)int?
python16進(jìn)制字符串轉(zhuǎn)int?這個(gè)轉(zhuǎn)了十進(jìn)制又轉(zhuǎn)了十六進(jìn)制,都是string,而不是數(shù)值print出來,是以string 輸出的。分享一個(gè)我以前的#比如hex.log 里面是E3F2A1#就要
python16進(jìn)制字符串轉(zhuǎn)int?
這個(gè)轉(zhuǎn)了十進(jìn)制又轉(zhuǎn)了十六進(jìn)制,都是string,而不是數(shù)值print出來,是以string 輸出的。分享一個(gè)我以前的#比如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 十六進(jìn)制查看
python16進(jìn)制轉(zhuǎn)字符串?
你的16進(jìn)制的串“C7EBCEF0BEC6BAF3BCDDB3B5”是gbk編碼的,通過以下方法可以轉(zhuǎn)為字符串。>>> s = "C7 EB CE F0 BE C6 BA F3 BC DD B3 B5">>> s = s.replace(" ", "")>>> print s.decode("hex")請(qǐng)勿酒后駕車