The binary representation of Integer.MIN_VALUE
in Java is 10000000000000000000000000000000
.
Why wouldn't it be 10000000000000000000000000000001
instead, since the addition of one to its two's complement would be larger than 10000000000000000000000000000000
by one?
int
in Java is a signed 32-bit number, meaning that the 32th bit, like you said, represents the negative number, in decimal, -(2^31)
, and in binary:
10000000000000000000000000000000
^ → "negative bit"
But the remaining 31 bits are still "positive" bits in a signed system, so:
10000000000000000000000000000001 → -2^31 + 1
And -2^31 + 1
is bigger than -2^31
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.