#include <stdio.h> #include <stdint.h> uint8_t compress_bits(uint16_t val) { // Your logic here uint8_t rev =0x0; uint8_t temp; int j=0; for(int i=0; i<16; i++) { temp = (val>>i) & 1; rev |= (temp << j); j++; i++; } //val &= 0x5555; //val = (val | val<<2) & 0x3333; //val = (val | val<<4) & 0X00FF; return rev; } int main() { uint16_t val; scanf("%hu", &val); uint8_t result = compress_bits(val); printf("%u", result); return 0; }
Test Cases
Test Results
Input
20548
Expected Output
202