Complete the code to perform a left bit shift by 1, which doubles the number.
const doubled = 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 the least significant bit of a number is 1 (odd number check).
const isOdd = (num & [1]) === 1;
Using bitwise AND with 1 checks the least significant bit. If it is 1, the number is odd.
Fix the error in the code to toggle the 3rd bit (bit index 2) of a number.
const toggled = num [1] (1 << 2);
The XOR operator (^) toggles bits. Using it with (1 << 2) flips the 3rd bit.
Fill both blanks to create a mask that clears the 3rd bit (bit index 2) of a number.
const mask = ~(1 [1] [2]);
Shift 1 left by 2 to get a mask for the 3rd bit, then invert it to clear that bit.
Fill all three blanks to create a function that sets the nth bit of a number.
function setBit(num: number, n: number): number {
return num [1] ([2] [3] n);
}Use OR (|) with 1 shifted left by n to set the nth bit of num.
