Java integers are 32-bit, and anything above the maximum value for a 32-bit number will get rolled over and become negative. This is known as integer overflow.
If you have:
int x = Integer.MAX_VALUE; x += 1;
x will equal
There is no such
From the Java docs:
int: By default, the int data type is a 32-bit signed two's complement integer, which has a minimum value of -2^31 and a maximum value of 2^31-1.
That max 32-bit value is equal to
0111 1111 1111 1111 1111 1111 1111 1111.
It's a 2's complement representation, so setting the 1st bit to 1 will result to a negative number (0x80000000 = 1000..0000). So, there's really no possible value for the
x you're looking for.
User contributions licensed under CC BY-SA 3.0