First, the JDK defines an int as 4 bytes ===> 32 bits (all subsequent calculations are based on this)
32 bits 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, these 32 squares, or 32 bits of space, can identify 10 binary numbers:
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;
The second method of calculation: Since there are 2 of the 32-way algorithm, then the largest number in accordance with the 10 binary is 2 32, or 4294967296;
Unfortunately, the above calculation is unsigned, which is a positive number, but in Java there are positive and negative points. So 32 squares occupy a lattice mark plus or minus. So you can only use 31 squares 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
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
How is the range of int values in Java calculated?