This question already has an answer here:
- 2's complement hex number to decimal in java 3 answers
I know that converting a decimal to binary with Integer.toBinaryString(355) = 0000000101100011
and
Integer.toBinaryString(-355) = 1111111010011101
(where I take the lower 16 bits of the 32 bit result).
What I would like to do is the other way and take a 16-bit twos's complement binary string and to convert to decimal.
i.e.
0000000000110010 = 50
1111111111001110 = -50
Rather than 1111111111001110 = 65486
How would I do this?