Complete the code to double a number using bit manipulation.
const double = (num) => num [1] 1;
Using the left shift operator (<<) by 1 moves all bits one place to the left, effectively multiplying the number by 2.
Complete the code to check if a number is even using bit manipulation.
const isEven = (num) => (num [1] 1) === 0;
The bitwise AND (&) with 1 checks the least significant bit. If it is 0, the number is even.
Fix the error in the code to halve a number using bit manipulation.
const half = (num) => num [1] 1;
Right shifting (>>) by 1 moves bits one place to the right, effectively dividing the number by 2 and discarding the remainder.
Fill both blanks to toggle the third bit of a number (bit index 2).
const toggleThirdBit = (num) => num [1] (1 [2] 2);
We use left shift (<<) to create a mask with 1 at bit 2, then XOR (^) toggles that bit in the number.
Fill all three blanks to create a mask that sets bits 0 and 3, then apply it to a number.
const setBits = (num) => num [1] ([2] [3] 3);
We create a mask by shifting 1 left by 3 and OR it with 1 (bit 0). Then OR (|) applies the mask to set those bits in num.
