We all know that bit operators are faster than normal operators, but why are they fast? First of all, our normal operators are also implemented by the computer through a bitwise operation Call stack. When the bitwise operator is evaluated, the operand is first converted to 2.
So what are the JavaScript bitwise operators?
1. & Bitwise AND
2. | Bitwise OR
3. ^ Bitwise XOR OR
4. ~ Take Back
5. >> bitwise LEFT Shift
6. >> Bitwise RIGHT Shift
Description
(1) The bitwise operator, except for ~, is a two-mesh operator, which requires an operand on each side.
(2) The operation can only be integer or character data, and cannot be a real data type.
1. Bitwise AND &
True if both the left and right values are true, otherwise false.
Console.log (5&7);//5
Detailed
2. Bitwise OR |
True if both the left and right values are true, otherwise false.
Console.log (5|7);//7
Detailed
3. Bitwise XOR ^
If the two binary numbers participating in the calculation are the same number, then it is 0 and the XOR is 1.
Console.log (true ^ true);//0
Console.log (true ^ false);//1
Console.log (false ^ false);//0
Console.log (false ^ true);//1
Detailed
4. Bitwise COUNTER ~
Console.log (~2.5);//-3 takes the inverse and then rounding down
5. Bitwise LEFT SHIFT <<
Explanation: Example: 5<<2 binary 5 to the left two bits, 0 on the right, also equivalent to 5*2^2, down rounding.
Console.log (5<<2);//20 5*x2*2=20
6. Bitwise RIGHT SHIFT >>
Explanation: Example: 5>>2 binary 5 to the right two bits, left 0, also equivalent to 5/2^2, down rounding.
Console.log (5>>2);//1 5*/(2*2) =1.25
On the computational method of bit operators