标签:进制 中文字符 文字 class int chinese color div pad
def Unicode2HexChar(Unicde_Char):#Unicode转16进制 Hex_Char = "" for i in range(0, len(Unicde_Char)): Hex_Char += (hex(ord(Unicde_Char[i])).replace(‘0x‘,‘‘).zfill(4)) return Hex_Char print(Unicode2HexChar(‘。‘)) def HexChar2Unicode(Hex_Char):#16进制转Unicode if len(Hex_Char)<5: Hex_Char=‘\\u‘+Hex_Char else: Hex_Char=pad(Hex_Char) return Hex_Char.encode().decode(‘unicode_escape‘) print(HexChar2Unicode(‘00B2‘)) def chineseToUnic(ch):#中文字符转16进制 return ch.encode(‘unicode_escape‘)[2:].decode(‘utf-8‘) print(chineseToUnic(‘飓‘))
python3 Unicode字符与16进制编码互转(单个字符)
标签:进制 中文字符 文字 class int chinese color div pad
原文地址:https://www.cnblogs.com/yanghao2008/p/10755616.html