Complete the code to initialize the result variable to zero.
let result = [1];We start with result as 0 because we will build the reversed bits from scratch.
Complete the code to extract the least significant bit from n.
let bit = n [1] 1;
Using bitwise AND (&) with 1 extracts the last bit of n.
Fix the error in the code to shift the result left by one bit.
result = result [1] 1;
Left shift (<<) moves bits to the left, making space for the next bit.
Fill both blanks to update result with the new bit and shift n right.
result = (result [1] bit); n = n [2] 1;
Use bitwise OR (|) to add the bit to result, and right shift (>>) to move n's bits right.
Fill all three blanks to complete the reverseBits function.
function reverseBits(n: number): number {
let result = [1];
for (let i = 0; i < 32; i++) {
let bit = n [2] 1;
result = (result << 1) [3] bit;
n = n >> 1;
}
return result;
}Initialize result to 0, extract bit with AND (&), add bit with OR (|), and shift result left before adding bit.
