pointers-memory · intermediate · ~14 min
Bitwise shifts and masking.
Reverse the order of all 32 bits in an unsigned 32-bit integer: bit 0 becomes bit 31, bit 1 becomes bit 30, and so on.
Implement uint32_t reverse_bits(uint32_t n) that returns n with its 32 bits in fully reversed order. No main — the grader calls it.
A single uint32_t n (0 to 0xFFFFFFFF).
Returns a uint32_t whose bit i equals the input's bit 31 - i.
reverse_bits(1) -> 0x80000000 (lowest bit moves to the top)
reverse_bits(0x55555555) -> 0xAAAAAAAA (every bit shifts one position)
reverse_bits(0xFFFFFFFF) -> 0xFFFFFFFF
n == 0 returns 0.Transfer exercise: apply the lesson to a complete function contract.
A single uint32_t n (0 to 0xFFFFFFFF).
Returns a uint32_t whose bit i equals the input's bit 31 - i.
Input and result are uint32_t. Reverse exactly 32 positions, including leading zeroes; unsigned operations only.
#include <stdint.h>
uint32_t reverse_bits(uint32_t n) { /* TODO */ return 0; }
Stopping when input becomes zero and dropping leading zero positions.
Zero; top/bottom bit; all ones; alternating bits.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.