Java Learning Journey-4

Source: Internet
Author: User

Bit operators in C did not learn, so it is new knowledge, as for the use, I am not very clear, first to see it.

&:

The two number of participating operations, if the value of the corresponding bits number is 1, then the result value is 1, otherwise 0, similar to "with", for example:

System.out.println(3 & 5);//结果为1运算过程如下:   00000011(3)   00000101(5)    &\\\\\\\\\\\\\\\\\\\\\\\\\\\\\      00000001(1)
|

As long as there is a 1 in the corresponding bit of the two number of participating operations, the result is 1, similar to "or", for example:

System.out.println(3 | 5);//结果为7运算过程如下:    00000011(3)    00000101(5)    |\\\\\\\\\\\\\\\\\\\\\\\\\\\\    00000111(7)
^:

The two numbers participating in the operation have the same corresponding bit and the result is 0, otherwise the result is 1, similar to XOR, for example:

System.out.println(3 ^ 5);//结果为6运算过程如下:    00000011(3)    00000101(5)   ^\\\\\\\\\\\\\\\\\\\\\\\\\\\\    00000110(6)
~

Change each bits ' 1 ' to ' 0 ', change ' 0 ' to ' 1 ', similar to reverse, for example:

System.out.println(~ 5);//结果为-6运算过程如下:    00000101(5)   ~\\\\\\\\\\\\\\\\\\\\\\\\\\\\    11111010(-6)

In fact, there are ' << ', ' >> ', ' >>> ' three bitwise operators, but it's a bit more difficult, so let's talk about it next time.

Java Learning Journey-4

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.