0.1. 字符串转字节串
字符串编码为字节码: '12abc'.encode('ascii') ==> b'12abc'
数字或字符数组: bytes([1,2, ord('1'),ord('2')]) ==> b'\x01\x0212'
16进制字符串: bytes().fromhex('010210') ==> b'\x01\x02\x10'
16进制字符串: bytes(map(ord, '\x01\x02\x31\x32')) ==> b'\x01\x0212'
16进制数组: bytes([0x01,0x02,0x31,0x32]) ==> b'\x01\x0212'
0.2. 字节串转字符串
字节码解码为字符串: bytes(b'\x31\x32\x61\x62').decode('ascii') ==> 12ab
字节串转16进制表示,夹带ascii: str(bytes(b'\x01\x0212'))[2:-1] ==> \x01\x0212
字节串转16进制表示,固定两个字符表示: str(binascii.b2a_hex(b'\x01\x0212'))[2:-1] ==> 01023132
字节串转16进制数组: [hex(x) for x in bytes(b'\x01\x0212')] ==> ['0x1', '0x2', '0x31', '0x32']