basics · beginner · ~15 min
Reverse the 8 bits of a byte.
Implement:
uint8_t reverse_byte(uint8_t b);
Return b with its 8 bits reversed.
A byte.
The bit-reversed byte.
None.
#include <stdint.h>
/* Reverse the 8 bits of a byte. */
uint8_t reverse_byte(uint8_t b){ return b; }
Letting the intermediate value exceed 8 bits without masking back to uint8_t.
0xA5 reverses to 0xA5 (palindrome); reversing twice is identity.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.