>>>" and ">>" in Java is: ">>" means right shift. If the number is positive, the high bits are filled with 0. If it is a negative number, the high bits are filled with 1; ">>>>" means Unsigned right shift. If the number is positive, the high bits are filled with 0. If the number is negative, the high bits are also filled with 0 after the right shift."/> >>>" and ">>" in Java is: ">>" means right shift. If the number is positive, the high bits are filled with 0. If it is a negative number, the high bits are filled with 1; ">>>>" means Unsigned right shift. If the number is positive, the high bits are filled with 0. If the number is negative, the high bits are also filled with 0 after the right shift.">

Home  >  Article  >  Java  >  The difference between >>> and >> in java

The difference between >>> and >> in java

王林
王林Original
2019-11-18 10:44:323139browse

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;

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

For example: The binary number of

res = 20 >> 2;

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;

-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;

The result is the same as >

##Supplement:

dd54f89b2799930951ef72add4bcc1e1>, 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!

Statement:
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