Java operators >, >>, >>> the difference between the three _java

Source: Internet
Author: User

> indicates greater than , such as: if (a>b) ... The result is a Boolean type

>> denotes a signed right shift , such as: int i=15; The result of the I>>2 is 3, and the removed part will be discarded.
The transition to binary may be better understood, with the result that 0000 1111 (15) to the right 2 digits is 0000 0011 (3), 0001 1010 (18) and the result of right shift 3 is 0000 0011 (3).

>>> no sign right shift :
In binary form, all the numbers to the right to move the corresponding towering digits, low move out (discard), high vacancy of 0. For positive numbers, it is the same as with the signed right, which is different for negative numbers.
Other structures and >> are similar.

The test code is as follows:

public class test{public  
  static void Main (string[] args) {  
    System.out.println ("1, the following test:");  
    int a = 1, b = 2;  
    System.out.println (a > B);  
    System.out.println ("\n2, the following test >>:");  
    System.out.println (">> 2 =" + (>> 2));  
    System.out.println ("\n3, the following test >>>:");  
    for (int i = 0; i < i++) {for  
      (int j = 0; J < + j = j + 5) {  
        System.out.println (j/(int) (Math.pow 2 , i));  
        System.out.println (J >>> i);}}} 

Other bitwise operators in Java:

~ Bitwise NON (not) (unary operation)
& Bitwise WITH (and)
| bitwise OR (OR)
^ Bitwise exclusive OR (XOR)
>> Move Right
>>> move right, left-empty bits are filled with 0
<< Move Left
&= Bitwise AND Assignment
|= bitwise OR ASSIGN Value
^= or assigned by bitwise
>>= Right Shift Assignment
>>>= to the right, the left blank bits are filled with 0
<<= left-shift assignment

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.