Given a positive integer such as 171 and a "register" size, e.g. 8.
I want the integer which is represented by the binary representation of 171, i.e. '0b10101011' interpreted as twos complement.
In the present case, the 171 should become -85. It is negative because given the "register" size 8, the MSB is 1.
I hope I managed to explain my problem. How can I do this conversion?
What I tried:
size = 8
value = 171
b = bin(value)
if b[len(b)-size] == '1':
print "signed"
# What to do next?