JS Bitwise AND ( & )
0001
&
0011
---
0001
A value of only two is 1 o'clock, which returns 1
JS Bitwise XOR or (^)
0101 (expression1)
1100 (expression2)
----
1001 (Result)
This bit of the result is 1 if and only if there is a bit on one expression that is 1 o'clock. Otherwise the result of this bit is 0.
JS bitwise OR (| )
0001
|
0011
0011
As long as one of the two numbers is 1, the result is 1, and the other is 0.
Bitwise non- (~)
Bitwise non-is to seek binary anti-code:
var num = 1; Binary 00000000000000000000000000000001
var num1 = ~num; Binary 11111111111111111111111111111110
We know that the numbers in JS are signed by default. The highest bit of the signed 32-bit binary means that the first digit is positive or negative, 1 represents a negative number, and 0 represents an integer. 11111111111111111111111111111110
How much is that? The highest bit is 1 for negative numbers, and the binary for negative numbers is converted to decimal: The sign bit is unchanged, the other bits are reversed plus 1. After the inverse 10000000000000000000000000000001
, plus 1 10000000000000000000000000000010
, the decimal is-2.
JavaScript logical operators