#include <stdio.h>
#include <stdint.h>
uint8_t compress_bits(uint16_t val) {
uint8_t result = 0;
// We loop 8 times because we are extracting 8 specific bits
for (int i = 0; i < 8; i++) {
// 1. Find the bit at the even position (i * 2)
// 2. Shift it down to the 0th position: (val >> (i * 2))
// 3. Mask it so we only have that one bit: & 1
// 4. Shift it to its new compact position: << i
// 5. Combine it with the result using bitwise OR
result |= ((val >> (i * 2)) & 1) << i;
}
return result;
}
int main() {
uint16_t val;
if (scanf("%hu", &val) == 1) {
uint8_t result = compress_bits(val);
printf("%u", result);
}
return 0;
}
Input
20548
Expected Output
202