Home > Java > Javagetting Started > body text

The difference between java >>> and >>

(*-*)浩
Release: 2019-11-11 11:54:14
Original
2446 people have browsed it

The difference between java >>> and >>

>>: Signed right shift. Positive numbers are shifted to the right and the high bits are filled with 0, and negative numbers are shifted to the right and the high bits are filled with 1s. For example:

4 >> 1, the result is 2; -4 >> 1, the result is -2. -2 >> 1, the result is -1.

>>>: Unsigned right shift. Regardless of whether it is a positive or negative number, the high bits are always filled with 0. (Recommended learning: java course)

For positive numbers, there is no difference between >> and >>>.

For negative numbers, -2 >>> 1, the result is 2147483647 (Integer.MAX_VALUE), -1 >>> 1, the result is 2147483647 (Integer.MAX_VALUE) ).

The following code can determine whether the signs of two numbers are equal

return ((a >> 31) ^ (b >> 31)) == 0;
Copy after login

For example:

-12 >> 3 is a signed right shift of 3 digits. The result is: 1111 1111 1111 1111 1111 1111 1111 1110. The decimal system is: -2;

-12 > Zero is: 0001 1111 1111 1111 1111 1111 1111 1110, in decimal: 536870910.

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