System.out.println(Integer.MAX_VALUE);
System.out.println(Integer.MIN_VALUE);
Prints:
2147483647
-2147483648
Why is the max value 2^31 -1 (the sign bit is 0 and does not add to the value of the number) and yet the min value is just -2^31 (the sign bit is 1 and does add to the value then??).
Think about it this way: you have as many binary patterns with the sign bit set to 1 as the number of binary patterns with the sign bit set to 0. However, you also need to represent zero, which is neither positive nor negative. Since zero is represented as a pattern of all zeros, it deducts from the set of positive numbers representable with the given number of bits, so the count of representable negative numbers is going to be greater by one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With