python进制转换
- 16进制串转字节串: bytes().fromhex('010210') ==> b'\x01\x02\x10'
- 16进制数组转字节串: bytes([0x01,0x02,0x31,0x32]) ==> b'\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']
- \x串中有可转字符时: bytes(map(ord, '\x01\x02\x31\x32')) ==> b'\x01\x0212'
字符串转整数:
- 10进制字符串: int('10') ==> 10
- 16进制字符串: int('10', 16) ==> 16
- 16进制字符串: int('0x10', 16) ==> 16