I need to cast bit sequences of arbitrary length to signed or unsigned integers. Those sequences are represented as strings. for example, I have to cast '001100100110100101110011001010'
to an unsigned integer and '10000000'
to a signed integer.
I used int('10000000', 2)
, but I haven't been able to find an intuitive approach to switch between signed/unsigned. Is there a straight-forward way to do this in Python?