#include <stdio.h> #include <stdint.h> uint16_t spread_bits(uint8_t val) { uint16_t reg = val; // Step 1: spread bits by 4 positions reg = (reg | (reg << 4)) & 0x0F0F; // Step 2: spread bits by 2 positions reg = (reg | (reg << 2)) & 0x3333; // Step 3: spread bits by 1 position reg = (reg | (reg << 1)) & 0x5555; return reg; } int main() { uint8_t val; scanf("%hhu", &val); uint16_t result = spread_bits(val); printf("%u", result); return 0; }
Test Cases
Test Results
Input
202
Expected Output
20548