A simple introduction to the Java bitwise operation

Source: Internet
Author: User

A bitwise operation is a change in the size of a number by the movement of the number after it is converted into binary.

1. & Bitwise AND

The two digits of the same bit are 1, or 1; if one is not 1, then 0.

2, | Bitwise OR

The same bit as long as one is 1 is 1, otherwise zero.

3, ^ bitwise XOR or

The same bit differs by 1, and the same is 0

4, ~ Bitwise reverse

1 takes 0, 0 takes 1.

5. << left Shift

Move left several, add several 0 behind

That is, multiply the number by 2 times.

6. >> Right Shift

Move right several, delete several

That means dividing the number by a few 2.

If the logarithm expands or shrinks by 2 times, it should be done by bitwise operation, so that the operation is much faster.

A simple introduction to the Java bitwise operation

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.