#include <stdio.h> #include <stdint.h> uint8_t reverse_bits(uint8_t n) { // Your logic here n = ((n >> 1) & 0x55) | ((n & 0x55) << 1); // Step 2: swap consecutive pairs n = ((n >> 2) & 0x33) | ((n & 0x33) << 2); // Step 3: swap nibbles n = (n >> 4) | (n << 4); return n; } int main() { uint8_t val; scanf("%hhu", &val); uint8_t result = reverse_bits(val); printf("%u", result); return 0; }
Test Cases
Test Results
Input
26
Expected Output
88