bit operations:
- Bitwise AND &;9&5; any operator has the result of the operation;
- For binary calculations, only two of the corresponding bits are 1 o'clock, the result is 1; otherwise 0;
- The function of the bitwise and is to know exactly which is what, to obtain a precise bits;
Bitwise OR |
- The corresponding two binaries have one 1 o'clock, which is 1;9|5
Bitwise XOR or ^
- 9 ^ 5; When two bits are not identical are for 1;
- The same value is different or, the result must be 0, such as 9 ^ 9 is 0;
- An XOR value can be exchanged for a position; 9^5^6 = = 9^6^5;
- Any value is different from 0, and the result is the original value;
- A^b^a==b
Bitwise inversion , including the sign bit;
- is the monocular operator;
Move left
- 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;
- The highest level of abandonment may lead to positive and negative changes;
Move right
- Move right one bit, is reserved sign bit, empty position with sign bit to complement; 8>>1 get 4;8>>2 get 2;
- 8>>n; gets 8/2 of the n-th square;
- Shift left is multiplication; right shift is division;
- 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;
- Take the value is bit with 1, print 9 out of 2, you can use the right shift method; number >>30 & 1;
- 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 &