← Go Back
To convert the binary number back to decimal use the
If you want to omit the
The prefix is also not necessary to convert back to integer:
How to Convert a Number to Binary (And Vice Versa)
Using thebin()
built-in function, which takes an integer and returns a string containing its binary representation:>>> bin(1234)
'0b10011010010'
To convert the binary number back to decimal use the
int()
built-in like this:>>> int('0b10011010010', 2)
1234
If you want to omit the
0b
prefix when converting from decimal to binary, you can do:>>> bin(1234)[2:]
'10011010010'
The prefix is also not necessary to convert back to integer:
>>> int('10011010010', 2)
1234
🐍 You might also find interesting: