Compress Interleaved Bits Reverse Bit Spreading

Code

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

uint8_t compress_bits(uint16_t val)

{
    uint8_t result=0;
    uint8_t output=0;
    int k=0;
    for(int j=0;j<16;j=j+2)
    {
    result  = (val>>j) & 1;
    output |= (result <<k);
    k++;
    }
    return output;
}

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