Compress Interleaved Bits Reverse Bit Spreading

Code

#include <stdio.h>
#include <stdint.h>
uint8_t compress_bits(uint16_t val) {
    // Your logic here
    for(int i=0,j=0;i<15;i+=2,j++)
    {
        if(val>>i&1)
        {
          val|=1<<j;
        }
        else
        val&=~(1<<j);
    }
    return val&0x00ff;
}
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