What is a bitwise operation
Bitwise operators are operated in binary, which can only be used for integer-type operations. such as: Char,short,int,long
Bitwise operators are used to get high and low values
int a=0x1234;
int high,low;
High = (a>>8) &0x00ff;
Low = A & 0x00ff;
Left and right shift operators (<< and >>)
The left shift is a binary number, move a number of bits, the right space out of the position filled with 0来, high left-shift overflow should discard the high.
such as: Inta = 8, a = 00001000;
A<<2 a = 00100000, so the value of a is a*2^2 = 32;
In the left-shift process, if this number overflows and discards the high level that does not contain 1, then the value of the move is the number of digits *2^ the value.
Right shift is a binary number, the right to move a number of bits, the left vacated position filled with 0来 (if it is unsigned type, if the signed type is based on the operating system requirements to complement.) Some operating systems are filled with symbol bits, and some operating systems are 0来 filled by default.
different or (^)
Two values that participate in binary operations are equal to 0, otherwise 1
1. With 0 different or, retain the original value
2. Exchange two values without a temporary variable
A=3,b=4
A= a^b;
b= b^a; (b=b^a^b)
A= a^b; (a^b^a^b^b)
The above C + + bit operator detailed explanation (XOR operator and shift operator) is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.