Home > Java > JavaBase > body text

The difference between >>> and >> in java

王林
Release: 2019-11-18 10:44:32
Original
3183 people have browsed it

The difference between >>> and >> in java

Bitwise operators in Java:

>>: means right shift. If the number is positive, the high bits are filled with 0. If it is a negative number, then Fill the high bits with 1;

>>>: Indicates unsigned right shift, also called logical right shift, that is, if the number is positive, the high bits will be filled with 0, and if the number is negative, the right The high bit after the shift is also filled with 0.

The expression is:

result = exp1 >> exp2;
result = exp2 >>> exp2;
Copy after login

means moving the number exp1 to the right by exp2 bits.

For example: The binary number of

res = 20 >> 2;
Copy after login

20 is 0001 0100. After shifting right by 2 bits, it is 0000 0101. The result is res = 5; the binary number of

res = -20 >> 2;
Copy after login

-20 Add 1 to the complement of its positive number, that is, 1110 1011. After shifting right by 2 bits, it is 1111 1100. The result is res = -6;

And for the >>> symbol:

res = 20 >>> 2;
Copy after login

The result is the same as >

##Supplement:

<< is the left shift operator corresponding to >>, which means moving exp1 to the left by exp2 bits and filling in the low bit with 0. In fact, moving n bits to the left is equivalent to multiplying by 2^n.

There is no <<< operator for left shift!

Recommended tutorial:

Java tutorial

The above is the detailed content of The difference between >>> and >> in java. 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!