Bitwise Operators
MediumIn plain terms
Bitwise operators work on 32-bit integers: & (AND), | (OR), ^ (XOR), ~ (NOT), << (left shift), >> (signed right shift), >>> (unsigned right shift). Used for low-level operations.
What you need to know
- •&, |, ^, ~, <<, >>, >>>
- •Operands converted to 32-bit integers
- •Useful for flags, permissions
Try it yourself
Copy the code below and run it in your browser console or a code editor:
5 & 1; // 1 (0101 & 0001)
5 | 1; // 5 (0101 | 0001)
5 ^ 1; // 4 (XOR)
~5; // -6 (bitwise NOT)
8 << 1; // 16 (multiply by 2)
8 >> 1; // 4 (divide by 2)
// Check if even
(6 & 1) === 0; // trueLearn more
Dive deeper with these trusted resources: