Compress Interleaved Bits Reverse Bit Spreading

Code

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

uint8_t compress_bits(uint16_t val) {
    // Your logic here
    int store =0;
    int count =14;
    while(count>0)
    {
        store =  store | ((val>>count) &1);
        store = store<<1;
        //printf("%d ",((val>>count) &1));
        //val = val>>2;
        count = count -2;
    }
    store = store |(val&1);
    return store;
}

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