bytes 转 hex
print(b'\x33\x74'.hex()) # 结果是 3374
print(b'123'.hex()) # 结果是 313233 因为1的ascii码是49 49用16进制表示是31
hex 转 bytes
print(bytes.fromhex('31323334')) # 结果是 b'1234'
print(bytes.fromhex('3374')) # 结果是 b'3t'
hex 转 int
print(int('31', 16)) # 结果是 49
print(int('66', 16)) # 结果是 102
int 转 hex
print(hex(63)) # 结果是 0x3f
print(hex(255)) # 结果是 0xff
int 转 bytes
(3273621578).to_bytes(4, 'little')
# 结果是 b'J\x80\x1f\xc3'
bytes 转 int
int.from_bytes(b'J\x80\x1f\xc3', 'little')
# 结果是 3273621578