Yesterday, the written test encountered a problem, so that the multiplication of the calculation method, design and optimization, and then summarize the relevant knowledge of the bit operations are as follows:
In the computer, the data is stored in 1010 binary form, 1bytes = 8 Bits,bit is a bit, so bit operation is to each 1010 operation.
Bitwise operations have &|~^<<>>, respectively, with or non-XOR or left shift right.
With: 1 with unchanged, 0 with for 0;
Or: only 0 or 0 is 0, other cases are 1;
Non: Take the reverse;
XOR: The same is 0, the difference is 1;
Shift left: Move several digits to the left/right;
Multiplication:
Move left one bit, equivalent to X2;
Division:
Shift right One bit,/2;
You do not need to apply for a third variable to achieve the exchange of 2 variable values:
Because a^b^a==b
So there are:
A=a^b;
B=a^b;
A=a^b;
C + + base-bit operations