The maximum value of java int is 2147483647. The int type number occupies 4 bytes. 1 byte is equal to 8 bits, that is, there are 32 bit placeholders. The calculation code is [for (int i = 0; i<= 30 ; i), tmp=tmp (1 << i);].
The maximum value of java int is: 2147483647
int The type number occupies 4 bytes.
1byte=8bit
That is, there are 32 bit placeholders
Can be obtained by bit shift operation
int tmp = 0; for (int i = 0; i <= 30; i++) tmp = tmp + (1 << i); System.out.println(tmp);
Isn’t it 32 bits? The calculation only goes to 30?
Since the highest bit of Int, that is, the 32nd, is not used to calculate the value, but is used to indicate whether the value is a positive or negative number, 0 represents a positive number, and 1 represents a negative number. Does not participate in value calculation.
So there are only 31 bits, which is one bit missing. The binary conversion starts from 0. During the shifting process, it moves to the 30th bit, which is the 31st bit value.
The above is the detailed content of What is the maximum value of java int. For more information, please follow other related articles on the PHP Chinese website!