Compress Interleaved Bits Reverse Bit Spreading

Code

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

uint8_t compress_bits(uint16_t val) {
    // Your logic here
    uint16_t pre = val;
    uint16_t kq =0;
    for(int i = 0; i<=7;i++)
    {
        val  = val & (1<< 2*i);
        kq = kq | val >> i;
        val = pre;
    }
    return kq;
    return 0;
}

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

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

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

20548

Expected Output

202