Challenge - 5 Problems
Bit Reversal Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of reversing bits for 8-bit number
What is the output of reversing the bits of the 8-bit number 13 (00001101 in binary)?
DSA C
unsigned char reverseBits(unsigned char n) {
unsigned char result = 0;
for (int i = 0; i < 8; i++) {
result <<= 1;
result |= (n & 1);
n >>= 1;
}
return result;
}
#include <stdio.h>
int main() {
unsigned char num = 13;
unsigned char reversed = reverseBits(num);
printf("%u\n", reversed);
return 0;
}Attempts:
2 left
💡 Hint
Think about how bits move from right to left when reversed.
✗ Incorrect
The binary of 13 is 00001101. Reversing bits gives 10110000 which is 176 in decimal.
❓ Predict Output
intermediate2:00remaining
Output of reversing bits for 16-bit number
What is the output of reversing the bits of the 16-bit number 4660 (0001001000110100 in binary)?
DSA C
unsigned short reverseBits16(unsigned short n) {
unsigned short result = 0;
for (int i = 0; i < 16; i++) {
result <<= 1;
result |= (n & 1);
n >>= 1;
}
return result;
}
#include <stdio.h>
int main() {
unsigned short num = 4660;
unsigned short reversed = reverseBits16(num);
printf("%u\n", reversed);
return 0;
}Attempts:
2 left
💡 Hint
Reverse the bits carefully from right to left for all 16 bits.
✗ Incorrect
4660 in binary is 0001001000110100. Reversing bits gives 0010110001001000 which is 11336 in decimal.
🔧 Debug
advanced2:00remaining
Identify the error in bit reversal code
What error does the following code produce when reversing bits of an 8-bit number?
DSA C
unsigned char reverseBits(unsigned char n) {
unsigned char result = 0;
for (int i = 0; i < 8; i++) {
result <<= 1;
result |= (n & 1);
n >>= 1;
}
return result;
}Attempts:
2 left
💡 Hint
Check the loop boundary condition carefully.
✗ Incorrect
The loop runs 9 times (i <= 8), but should run 8 times (i < 8). The extra iteration shifts bits incorrectly causing wrong output.
❓ Predict Output
advanced2:00remaining
Output of reversing bits for 32-bit number
What is the output of reversing the bits of the 32-bit number 43261596 (00000010100101000001111010011100 in binary)?
DSA C
unsigned int reverseBits32(unsigned int n) { unsigned int result = 0; for (int i = 0; i < 32; i++) { result <<= 1; result |= (n & 1); n >>= 1; } return result; } #include <stdio.h> int main() { unsigned int num = 43261596; unsigned int reversed = reverseBits32(num); printf("%u\n", reversed); return 0; }
Attempts:
2 left
💡 Hint
Reverse all 32 bits carefully.
✗ Incorrect
43261596 binary reversed is 00111001011110000010100101000000 which is 964176192 decimal.
🧠 Conceptual
expert2:00remaining
Why is bit reversal useful in algorithms?
Which of the following is the main reason bit reversal is used in algorithms like Fast Fourier Transform (FFT)?
Attempts:
2 left
💡 Hint
Think about how FFT processes data in stages.
✗ Incorrect
Bit reversal reorders input indices to enable efficient recursive processing in FFT algorithms.
