Python: Convert Bytes to Integer in Python 3.x – A Beginner Guide

In this tutorial, we will use an example to show you how to convert bytes to int in python 3.x.

Python: Convert Bytes to Integer in Python 3.x - A Beginner Guide

>>> testBytes = b'\xF1\x10'
>>> int.from_bytes(testBytes, byteorder='big')
61712

In this example code, we will use int.from_bytes() to convert bytes to int. However, as to int, there areĀ signed or unsigned.

If you want to convert to signed integer, you can do as follows:

>>> testBytes = b'\xF1\x10'
>>> int.from_bytes(testBytes, byteorder='big', signed=True)
-3824

Here we setĀ signed=True to convert bytes to signed integer.