JAVASCRIPT Tutorial
Bitwise operators are used to perform operations on individual bits of numbers. They include:
Bitwise AND (&)
Bitwise OR (|)
Bitwise XOR (^)
Bitwise NOT (~)
Left Shift (<<)
Right Shift (>>)
Unsigned Right Shift (>>>)
const a = 10; // 1010 in binary
const b = 5; // 0101 in binary
console.log(a & b); // 0000 (AND: both bits must be 1)
console.log(a | b); // 1111 (OR: either bit is 1)
console.log(a ^ b); // 1111 (XOR: bits must be different)
console.log(~a); // 1101 (NOT: inverts bits)
console.log(a << 2); // 101000 (Left shift: adds 0s)
console.log(a >> 2); // 0010 (Right shift: loses 1s)
console.log(a >>> 2); // 0010 (Unsigned right shift: loses 0s)