# 任意进制转化,c:int->str(不带有0b、0o、0x前缀)
"{:02x}".format(c)
"{:02b}".format(c)
"{:02o}".format(c)
"{:02}".format(c)
# 10进制转化,c:int->str,分别带有0b、0o、0x前缀
bin(123) # '0b1111011'
oct(123) # '0o173'
hex(123) # '0x7b'
# 任意进制转化10进制
int(x)
int(0xdf)
int(0o23)
int(0b1111)
# 字符串 -> 十六进制
binascii.a2b_hex('e4b8ade69687e6b58be8af95e794a8e4be8b')
binascii.unhexlify('e4b8ade69687e6b58be8af95e794a8e4be8b')
# 十六进制 -> 字符串
data = "大的啊".encode("utf8")
binascii.b2a_hex(data) # 接受参数bytes
binascii.hexlify(data)
python3对于进制的转化
于 2021-08-17 10:57:30 首次发布