Home > Java > javaTutorial > body text

What is the maximum value of java int

coldplay.xixi
Release: 2020-09-11 15:01:45
Original
26877 people have browsed it

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);].

What is the maximum value of java int

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!