------iOS training, Java training, Android training, iOS learning technology blog, looking forward to communicating with you------
Bitwise AND &
1101110 101101
0110101 000100
——————— ---------------
0100100 000100
in situ and 1&, remained unchanged; and 0&, all 0
Therefore, you can let the original number of a bit with 1&, according to the result can determine whether the bit is 0 or 1, and the result is only 0 or 1
A&1==1//a is odd because the last digit of the odd number is 1.
A&1==0//a is even, because the last digit of the even number is 0.
outputs a binary form of an integer
void printbinary (int num) {
// with the right shift, each bit of &1 Gets the value of each bit printed
// define variables, record the number of bits that are shifted right
// right Shift after &1 bit gets the first bit value 0 or 1
//(sizeof (num) <<3) -1==4*8-1==31
for ( int count= (sizeof) <<3)-1; count>=0; count-- ) {
printf ("%d",(num>>count) &1); any number &1 results can only be 0 or 1
If (! ( count%4)) {
printf ("");
If (! ( count%8)) {
printf ("");
}
}
}
printf ("\ n");
}
Bitwise OR |
010110 101101
011100 000000
——————— ---------------
011110 101101
A|0=a
Bitwise XOR or ^
Each one is 0 and the difference is 1. and can be exchanged
A^b^c==a^c^b==b^a^c
A^a==0
A^0==a
A^b^a==b
The interchange A^b^a==a^a^b==0^b==b of A and B values using bitwise XOR or ^ operations
A=a^b;
B=a^b;
A=a^b;
Shift left <<
a<<n==a*2 N-Th square
But left shifts can lead to positive and negative changes.
Shift Right >>
A>>N==A/2 N-Th square
Positive and negative changes
Dark Horse Programmer---C language---memory profiling