#include <stdio.h> #include <stdint.h> #define SET_BIT(reg, n) ((reg) |= 1 << (n)) #define CHECK_LAST_BIT(reg) ((reg) & 1U) uint16_t spread_bits(uint8_t val) { // Your logic here uint16_t res = 0; for(int i = 0; i < 16; i++){ if(i % 2 == 0){ if(CHECK_LAST_BIT(val)){ SET_BIT(res, i); } val = val >> 1U; } } return res; } 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