I'd simply like to convert a base-2 binary number string into an int, something like this:
>>> '11111111'.fromBinaryToInt() 255
Is there a way to do this in Python?
You use the built-in int() function, and pass it the base of the input number, i.e. 2 for a binary number:
int()
2
>>> int('11111111', 2) 255
Here is documentation for Python 2, and for Python 3.
2.1m questions
2.1m answers
60 comments
57.0k users