Challenge - 5 Problems
Bit Reversal Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of reversing bits of 13 in 8-bit representation?
Given the 8-bit binary representation of the number 13, what is the decimal value after reversing its bits?
DSA Python
def reverse_bits(n, bits=8): result = 0 for _ in range(bits): result = (result << 1) | (n & 1) n >>= 1 return result print(reverse_bits(13))
Attempts:
2 left
💡 Hint
Think about the binary form of 13: 00001101. Reverse the bits and convert back to decimal.
✗ Incorrect
13 in 8 bits is 00001101. Reversing bits gives 10110000 which is 176 in decimal.
❓ Predict Output
intermediate2:00remaining
What is the output of reversing bits of 1 in 4-bit representation?
What decimal number results from reversing the bits of 1 using 4 bits?
DSA Python
def reverse_bits(n, bits=4): result = 0 for _ in range(bits): result = (result << 1) | (n & 1) n >>= 1 return result print(reverse_bits(1, 4))
Attempts:
2 left
💡 Hint
1 in 4 bits is 0001. Reverse bits and convert to decimal.
✗ Incorrect
0001 reversed is 1000 which equals 8 in decimal.
🔧 Debug
advanced2:00remaining
What error does this code raise when reversing bits?
Identify the error raised by this code snippet when reversing bits of 5 in 3 bits:
DSA Python
def reverse_bits(n, bits=3): result = 0 for i in range(bits): result = (result << 1) | (n & 1) n = n >> 1 return result print(reverse_bits(5))
Attempts:
2 left
💡 Hint
Check if the code runs without exceptions and what output it produces.
✗ Incorrect
The code correctly reverses bits of 5 (101) in 3 bits to 101 which is 5 decimal. No error occurs.
❓ Predict Output
advanced2:00remaining
What is the output of reversing bits of 19 in 5-bit representation?
Calculate the decimal value after reversing the 5-bit binary representation of 19.
DSA Python
def reverse_bits(n, bits=5): result = 0 for _ in range(bits): result = (result << 1) | (n & 1) n >>= 1 return result print(reverse_bits(19, 5))
Attempts:
2 left
💡 Hint
19 in 5 bits is 10011. Reverse bits and convert to decimal.
✗ Incorrect
10011 reversed is 11001 which equals 25 decimal.
🧠 Conceptual
expert2:00remaining
How many bits are needed to reverse bits of the number 1023 correctly?
To reverse the bits of the number 1023 correctly, how many bits should be used in the reversal process?
Attempts:
2 left
💡 Hint
Think about the binary length of 1023.
✗ Incorrect
1023 in binary is 1111111111 which is 10 bits long, so 10 bits are needed to reverse it correctly.