All submissions

Compress Interleaved Bits Reverse Bit Spreading

Code

#include <stdio.h>
#include <stdint.h>

uint8_t compress_bits(uint16_t val) {
    uint8_t value = 0;
    int bit_pos = 0;
    for (int i = 0; i < 16; i++) {
        if ((i % 2) == 0) {
            //Extract bit and then place it at bit_pos
            value |= ((val >> i) & (1U<<0)) << bit_pos;
            bit_pos++;
        }
    }

    return value;
}

int main() {
    uint16_t val;
    scanf("%hu", &val);

    uint8_t result = compress_bits(val);
    printf("%u", result);
    return 0;
}

Solving Approach

 

 

 

Loading...

Input

20548

Expected Output

202