Java thousand asked _03 Basic grammar (013) _>, >>, >>> what is the difference

Source: Internet
Author: User
Tags bitwise bitwise operators

Click to enter _ more _java thousand ask

1, >, >>, >>> what is the difference

See Java operators here: What are the operators of Java
Understanding Java Operator Precedence See here: What is the precedence of Java operators
">" belongs to relational operators, while ">>", ">>>" bitwise operators look at their respective meanings:

    1. Operators >
      The relational operator, which represents greater than.
      such as: if (a>b) ... The result is a Boolean type.

    2. Operators >>
      A bitwise operator that represents the right shift. << represents a left shift.
      j<< i. Equals num divided by 2 n power, j/(int) (Math.pow (2, i)).
      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, 0 0000 1111 (15) The result of moving the 2-bit right is 0 0000 0011 (3).
      Understanding binary operations See here: How binary is doing bit arithmetic

    3. Operators >>>
      A bitwise operator that represents the unsigned right shift.
      Similar to >>, but ignores the sign bit while moving, and the empty space is padded with 0.
      The unsigned Right shift operator >>> is only meaningful (and negative) for 32-bit and 64-bit values, and the rest is consistent with >>.

Instance:

System. out. println("1, the following test;:");int a = the, B =2, C =- the;System. out. println(A > B);System. out. println("\n2, the following test >>:");System. out. println(A +"/(int) (Math.pow (2,"+ B +"))) = "+ (A/(int) (Math. Pow(2, b))));System. out. println(A +">>"+ B +" = "+ (a >> b));System. out. println(C +">>"+ B +" = "+ (c >> b));System. out. println("\N3, the following test >>>:");System. out. println(A +">>>"+ B +" = "+ (a >>> b));System. out. println(C +">>>"+ B +" = "+ (c >>> b));

The results of the implementation are as follows:

1, the following test;:
True
2, the following test >>:
(int) (Math.pow (2, 2)) = 3
>> 2 = 3
-15 >> 2 =-4
3, the following test >>>:
>>> 2 = 3
-15 >>> 2 = 1073741820

Java thousand asked _03 Basic grammar (013) _>, >>, >>> what is the difference

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.