#include <stdio.h> #include <stdint.h> uint16_t spread_bits(uint8_t val) { // Your logic here bool b; char i = 0; uint16_t res = 0; while(i<8){ b = (val >> i) & 1U; res |= (b << (2*i)); i++; } return res; } int main() { uint8_t val; scanf("%hhu", &val); uint16_t result = spread_bits(val); printf("%u", result); return 0; }
Extract the relevant bit and shift it by the position and then or back into the previous result.
Test Cases
Test Results
Input
202
Expected Output
20548