Convert base-2 binary number string to int
Another way to do this is by using the bitstring
module:
>>> from bitstring import BitArray>>> b = BitArray(bin='11111111')>>> b.uint255
Note that the unsigned integer is different from the signed integer:
>>> b.int-1
The bitstring
module isn't a requirement, but it has lots of performant methods for turning input into and from bits into other forms, as well as manipulating them.