Reverse Bits in a Byte
Write a C function that reverses the bit order of an 8-bit value, so bit 0 becomes bit 7, bit 1 becomes bit 6, and so on. This shows up constantly when a peripheral shifts data MSB-first but your protocol layer expects LSB-first.
Constraints
- Signature must be `uint8_t reverse_bits(uint8_t value)`.
- No loops over a lookup table larger than 16 bytes.
- Must run in constant time regardless of input.
- Do not use compiler builtins such as __builtin_bitreverse8.
- No dynamic memory.
1#include <stdint.h>2 3uint8_t reverse_bits(uint8_t value) {4 // TODO: reverse the bit order5 return 0;6}