Bitwise operator ACTION

Source: Internet
Author: User

1. Bitwise AND operator (&)

Since any one is the result of the 0,& operation, it is 0, so you can use this operator to set the unnecessary bits in the variable to 0. The method is to create a ' mask ' and then use & to combine it with the original variable. such as: Letter=letter & 0x0F;

2. Bitwise OR operator (|)

One of the two bits is the result of the 1,or operation is 1, so the result of these two variables is that both bits are opened, such as: Style |= Hredraw | Vredraw;

3. Bitwise EOR operator (^)

Letter1 0100 0001

Letter2 0101 1010

After the EOR operation, they are:

Result 0001 1011

The XOR operator has an attribute, and the two variables exchange values without occupying any intermediate storage units. This applies to all integer values. Such as:

First ^= last; Result First is 0001 1011

Last ^= first; Result is 0100 0001

First ^= last; Result First is 0101 1010

4. Bitwise NOT operator (~)

The position of the number is reversed, 1 change 0,0 to 1.

5. Shift Operator (<<) (>>)

Moving the N-bit to the left is equivalent to multiplying the value by 2 n times, which is equivalent to 2n times. Moving right is equivalent to excluding.

Bitwise operator ACTION

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.