
Int(x = b_string, base = 2) # Convert to base 2.Īpproach 2: Using bitmasking and left shift operatorīefore moving forward, it is necessary to understand how we convert the binary number to its decimal form.

# Now, convert back the binary string to integer with int() and base parameter. Print(b_string) # Print the binary string representation.

However, we can also convert the string literal of the different base to the integer with the help of kwarg base. You must have seen int() when you wanted to typecast float or string to the integer format.

Approach 1: Using method int() + base argument
