1.NOT
The bitwise operator is not represented by ~. The essence of the not operator is to negate the number and then subtract 1.
The bitwise operator NOT is a three-step process.
A. Converting an operator to a 32-digit number
B. Converting binary form to its binary counter code
C. Converting binary inverse codes to floating point numbers
Example:
var num=10; document.write (~num);
Results:
-11
2.AND
The bitwise operator and is represented by &. Directly to the binary form of the number. The arithmetic rules are as follows:
First number |
A second number |
Results |
0 |
0 |
0 |
0 |
1 |
0 |
1 |
0 |
0 |
1 |
1 |
1 |
Example:
var num1=10;
Results:
Binary representation of 10 1010
3.OR
The bitwise operator or is represented by a symbol |. directly to the binary, the rules are as follows:
First number |
A second number |
Results |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
0 |
1 |
1 |
1 |
1 |
Example:
var num1=10;
Results:
The binary representation of 11 is 1011
4.XOR
The bitwise operator XOR is represented by the symbol ^. Direct binary operation. The rules are as follows:
First number |
A second number |
Results |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
0 |
1 |
1 |
1 |
0 |
Example:
var num1=10;
Results:
The binary representation of 1 is 1
5.<<
The left shift operator is represented by <<. It moves all digits in the number to the left by the specified number.
Attention:
A. When you move the digits to the left, the empty space on the right side of the number is filled with zeros so that the result is a full 32-digit number
B. The left shift retains the sign bit of the number.
Example:
document.write (10<<2+"<br/>"); document.write ( -10<<2);
Effect:
6.>>
A signed right-shift operation is represented by >>. It shifts all the numbers in the 32-digit number to the right. The symbol for that number is preserved at the same time.
Attention:
A. The sign bit remains the same
B. When you shift the digits to the right, the left seat of the number is filled by 0
Example:
document.write (10>>1); document.write ("<br/>"); document.write ( -10>>1);
Effect:
7.>>>
Unsigned right shift is represented by >>>. It shifts all the numbers in a 32-digit number to the right.
Attention:
A. Unsigned right-shift operation fills all vacancies with 0.
B. For integers, the unsigned right shift is the same as the signed right shift result.
C. For negative numbers, because the left side of 0, resulting in negative numbers after the unsigned right shift, becomes a positive number
For example:
document.write ( -10>>>1);
Results:
Operation Process:
-10
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
0 |
1 |
1 |
0 |
Unsigned Right Shift -10>>>1
0 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
0 |
1 |
1 |
Results:
2147483643
javascript--Bitwise operators