I have calculated the 2's complement of a binary number and represented it in the Binary format. Now, I am trying to convert the 18-bit Signed Binary Number to decimal numbers (-131072 to +131072).
When I use the int function it only gives unsigend values:-
number = 111111111111111110
print(int(str(number), 2))
Output = 262142
Any suggestions would be highly appreciated. Thanks!
0b111111111111111110and saved some time on conversions.0b111111111111111110as the other user suggests, you just parse the digit sequence once as binary.