According to my comprehension, Integer type in Java is 32-bit-signed, the most significant bit is the signed bit. This is why Integer.MAX_VALUE is 2147483647, which is:
1111111111111111111111111111111(1 repeated in 31 times).
So I assume that it actually can be represented as:
01111111111111111111111111111111(a 0 followed by 1 repeated 31 times)
The 0 means this is a positive integer.
Then for the following codes:
int test = -2147483647;
String converted = Integer.toBinaryString(test);
System.out.println(converted);
The output is:
10000000000000000000000000000001
Why the output is like above? For me, the binary stream should be represented as -1, since the most significant bit is 1 means negative.
Like this:
int minusOne = -1;
String converted1 = Integer.toBinaryString(test);
System.out.println(converted1);
The output is the same as above:
10000000000000000000000000000001
Any explanation?