See en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
Bitwise binary operator may also be used as assignment operator
The bitwise arithmetic operators
They are also Boolean operator.
// ~x is roughly the same as -(x+1)
console.log(~2); // -(2+1) ==> -3
The bitwise addition, modulo 2, of two bit strings of equal length.
The bitwise XOR expression follows the following rules:
0 ^ 0 = 0
0 ^ 1 = 1
1 ^ 0 = 1
1 ^ 1 = 0
Example
console.log(6 ^ 2); // 110 ^ 010 = 100 = 4
The bitwise OR expression follows the following rules:
0 | 0 = 0
0 | 1 = 1
1 | 0 = 1
1 | 1 = 1
Example:
console.log(6 | 2); // 110 ^ 010 = 110 = 6
console.log(8 | 1); // 1000 ^ 0001 = 1001 = 9
0 & 0 = 0
0 & 1 = 0
1 & 0 = 0
1 & 1 = 1
The shift operators shifts the digits to the left or to the right:
List:
Example / Demo:
const foo = '0001'; // 1
console.log(`Initial Value: bit: ${foo}, decimal ${parseInt(foo, 2)}`);
let fooShifted = parseInt(foo, 2) << 1
console.log(`shifted by one (x2): bit: ${fooShifted.toString(2)}, decimal: ${fooShifted}`);
fooShifted = parseInt(foo, 2) << 2
console.log(`shifted by two (x2 x2): bit: ${fooShifted.toString(2)}, decimal: ${fooShifted}`);