字符串与16进制的互相转换
原文:https://blog.51cto.com/topic/pythonzifuchuanzhuanhuanchengshiliujinzhi.html
一,使用binascii模块
import binascii
s=b'hello'
a=binascii.b2a_hex(s)
b=binascii.a2b_hex(a)
结果b'68656c6c6f'
二,使用base64模块
import base64
s=b'hello'
a=base64.b16encode(s)
b=base64.b16decode(a)
结果b'68656C6C6F'
解析:
1.第一种方法,转换过去是小写字母,第二种是大写字母。