The difference between >, >>, >>> in Java

Source: Internet
Author: User

> represents greater than, for example: if (a>b) ... The result is a Boolean type.


>> to move right, such as: int i=15; The result of the I>>2 is 3, and the removed part will be discarded.


The conversion to binary may be better understood, 0000 1111 (15) The result of the right shift 2 bits is 0000 0011 (3), 0001 1010 (18) The result of the right shift 3 bits is 0000 0011 (3).

The ">>>" operator does an unsigned displacement processing, which does not treat the highest bit of the value being treated as a positive sign, so when the displacement is processed, it is filled in 0 directly at the vacated high. This kind of unsigned displacement may be required when the original value of the displacement is not represented by the value (for example, the values representing the color element, the highest digit is not a sign).


Using the >>>= operator and using the following statement is equivalent:
result = result >>> expression
The >>>= operator shifts all bits of result to the right by the number of digits specified by expression. The left-vacated bits after the right shift are filled with zero. The bits that are moved to the right are discarded. For example:

var temp
temp =-14
Temp >>>= 2

The difference between >, >>, >>> in Java

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.