Bitwise operations: C Bitwise AND &

Source: Internet
Author: User

bit operations:
    1. Bitwise AND &;9&5; any operator has the result of the operation;
    2. For binary calculations, only two of the corresponding bits are 1 o'clock, the result is 1; otherwise 0;
    3. The function of the bitwise and is to know exactly which is what, to obtain a precise bits;

Bitwise OR |

    1. The corresponding two binaries have one 1 o'clock, which is 1;9|5

Bitwise XOR or ^

    1. 9 ^ 5; When two bits are not identical are for 1;
    2. The same value is different or, the result must be 0, such as 9 ^ 9 is 0;
    3. An XOR value can be exchanged for a position; 9^5^6 = = 9^6^5;
    4. Any value is different from 0, and the result is the original value;
    5. A^b^a==b

Bitwise inversion , including the sign bit;

    1. is the monocular operator;

Move left

    1. 9<<1; the whole number to the left to move N-bit (a<<n), to the left of a move, the highest will be discarded, the lowest 0;9 to the left, is the 9*2 of 1 ==18; move to the left 2, that is, 9*2 2-square ==36;
    2. The highest level of abandonment may lead to positive and negative changes;

Move right

    1. Move right one bit, is reserved sign bit, empty position with sign bit to complement; 8>>1 get 4;8>>2 get 2;
    2. 8>>n; gets 8/2 of the n-th square;
    3. Shift left is multiplication; right shift is division;
    4. A=b-1;b=b-a;a=b+a; or a = A^b;b=a^b;a=a^b; a&1 ==1 is odd with bit and operation; A&1 ==0 is even;
    5. Take the value is bit with 1, print 9 out of 2, you can use the right shift method; number >>30 & 1;
    6. int temp = (sizeof (number) <<3) -1;while (temp>=0) {int value = number>>temp & 1;printf ("%d", value); Temp--;if ((temp+1)%4==0) {printf ("")}}printf ("\ n")

Bitwise operations: C Bitwise AND &

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.