import binascii hex_b = 'f0148c' bytes_be = binascii.unhexlify(hex_b) bytes_le = bytes_be[::-1] hex_le = binascii.hexlify(bytes_le).decode() print(hex_le)
import sys
def dump(data):
print(data)
a = int.from_bytes(data, byteorder='big')
b = int.from_bytes(data, byteorder='little')
c = int.from_bytes(data, byteorder=sys.byteorder)
print(a, hex(a))
print(b, hex(b))
print(c, hex(c))
dump(b'\x01\x02')
dump(b'\x11\x12\x13\x14\x15\x16\x17\x18\x19')
$ python3 test.py
b’\x01\x02′
258 0x102
513 0x201
513 0x201
b’\x11\x12\x13\x14\x15\x16\x17\x18\x19′
314897056051100063769 0x111213141516171819
462904482303900324369 0x191817161514131211
462904482303900324369 0x191817161514131211