All submissions

Extract Even Bits Only from 32-bit Register

Code

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

uint32_t extract_even_bits(uint32_t reg) {
    uint8_t i = 0, ii = 0;
    uint8_t position = 0;
    uint32_t outreg = 0;

    while(i < 32){
        if((reg >> i) & 1) outreg = outreg|(1U << ii);
        i = i + 2;
        ii = ii + 1;
    }

    return outreg;
}

int main() {
    uint32_t reg;
    scanf("%u", &reg);
    printf("%u", extract_even_bits(reg));
    return 0;
}

Solving Approach

 

 

 

Loading...

Input

85

Expected Output

15