This post will discuss how to convert a binary string to an integer in Python.

1. Using int() function

The standard way to convert a binary string to an integer is using the built-in function int. You need to pass base 2 for a binary number.

Download  Run Code

2. Using bitstring module

Another alternative is to use the bitstring module, as shown below:

Download Code

That’s all about converting a binary string to an integer in Python.