Python 字符串和16进制的相互转换
2022-03-16 本文已影响0人
JP0001
def str_to_hex(self,s):
# 文本转16进制
return ' '.join([hex(ord(c)).replace('0x', '') for c in s])
def hex_to_str(self,s):
#16进制转为文本
return ''.join([chr(i) for i in [int(b, 16) for b in s.split(' ')]])