Bitwise Operators: ================== The operations can define bit by bit (bitwise) 10 ==> 1010 0 ==> 0000 1 ==> 0001 2 ==> 0010 3 ==> 0011 4 ==> 0100 5 ==> 0101 6 ==> 0110 7 ==> 0111 8 ==> 1000 9 ==> 1001 10 ==> 1010 11 ==> 1011 12 ==> 1100 13 ==> 1101 14 ==> 1110 15 ==> 1111 ====== ==> the bitwise operators are: 1) Bitwise and ==> & 2) Bitwise or ==> | 3) Bitwise xor ==> ^ 4) Bitwise Complement ==> ~ 5) Left Shift Operator ==> << 6) Right Shift Operator ==> >> 7) Unsigned Right Shift Operator ==> >>> Bitwise and ==> & ========================= ==> Binary Operator Syntax: operand1 & operand2 a b a & b ====================== 0 0 0 0 1 0 1 0 0 1 1 1 ex: 2 & 3 2 ==> 0010 3 ==> 0011 =========== & ==> 0010 ==> 2 1.2 & 2.3 Note: ==== We can allowed to define the bitwise operations on Boolean values also. var a = 11; let b = 10; console.log(a & b); console.log(1.2 & 2.3); console.log(true & true); console.log(true & false); console.log(false & true); console.log(false & false); console.log('a' & 'b'); console.log('abc' & 'def'); ======================================= Bitwise Or ==> | ================ ==> Binary Operator Syntax: operand1 | operand2 a b a | b ===================== 0 0 0 0 1 1 1 0 1 1 1 1 ex: 9 | 8 9 ==> 1001 8 ==> 1000 ============ | ==> 1001 ==> 9 console.log(9 | 8); console.log(12.12 | 13.12); console.log(true | true); console.log(true | false); console.log(false | true); console.log(false | false); console.log('a' | 'r'); ============================================== Bitwise Xor ==> ^ ================= ==> Binary Operator Syntax: operand1 ^ operand2 a b a ^ b ====================== 1 1 0 1 0 1 0 1 1 0 0 0 ex: 12 ^ 13 12 ==> 1100 13 ==> 1101 ============ ^ ==> 0001 ==> 1 console.log(12 ^ 13); ============================================= Bitwise Complement ==> ~ ========================= ==> Unary Operator Syntax: ~operand ==> can invert the data by performing the 2's complement operation. + ==> - - ==> + console.log(~0); console.log(~1); console.log(~-8); =========================================== Left Shift Operator =================== << Syntax: operand << n.times Note: ==== For every left shift operation, the value should be doubled. Math Equation: ============= data X 2 ^n Right Shift Operator (>>) ======================== Syntax: operand >> n Note: ==== For every right shift operation, the data should be halved. Unsigned Right shift Operator: ============================== >>> Syntax: operand >>> n Note: ==== can be applicable to positive numbers only. console.log(8 << 2); console.log(8 >> 2); console.log(8 >>> 2); console.log(-8 >>> 2);