icon

Convert Bytes to Int in Python

Last modified: 2023-08-29

Converting bytes to int is easily done by int.from_bytes method in python.

Conversion

Big Endian

For using big endian, we can specify "big" to the byteorder argument (the second argument) of int.from_bytes method in Python.

int.from_bytes(b'hello', byteorder='big')
# 448378203247

int.from_bytes(b'\x00\x01', byteorder='big')
# 1

Little Endian

For using little endian, we can specify "little" to the byteorder argument (the second argument) of int.from_bytes method in Python.

int.from_bytes(b'hello', byteorder='little')
# 478560413032

int.from_bytes(b'\x00\x01', byteorder='little')
# 256