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) {
    // Your code here
    uint32_t mask = 0x0000;
    uint32_t x = 0;
    if (reg == 0) return 0;

    while(1)
    {
        //check even numbers
        if(reg & (1 << x*2))
        {
            //assign value
            mask |= (1 << (x));
        }
        
        if (x == 15)
        {
            break;
        }
        x++;
    }
    return mask;
}

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

Solving Approach

 

 

 

Loading...

Input

85

Expected Output

15