The first definition of an int in the JDK is 4 bytes ===> 32 bits (all subsequent calculations are based on this)
The 32-bit is the JVM that allocates only 32 squares of space for storing data.
It is well known that computers store data in 0 and 1.
Then, the 32-lattice 0 or 1 method has 2 32-time species:
So. In these 32 squares. Or a 32-bit space that identifies 10 decimal digits:
Minimum
| 0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
Biggest
| 1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
The first method of calculation: The binary maximum number (32 1) is converted to 10 binary, that is, 4294967296;
Another method of calculation: Since there are 2 of the 32-way algorithm, then the largest number according to the 10 binary is 2 32 times. i.e. 4294967296;
Pity. The above calculation is unsigned. is a positive number. But in Java, there are positive and negative points in Int. So 32 squares occupy a lattice mark plus or minus.
So only 31 squares can be used to identify values.
:
| X |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
X is 0 to identify positive or negative.
The last int can be identified by the maximum/minimum number is: 2 of 31 Square: +/-2147483648
How is the range of int values in Java calculated?