#include <stdio.h>
#include <stdint.h>
uint32_t extract_even_bits(uint32_t reg) {
// Your code here
int n = 0;
uint32_t evenReg = 0b0;
for(size_t i = 0; i<32; i+=2){
//shift the even positions of reg to position 0 and extract.
//Next thing is to put the extracted bit in the required position in evenReg
evenReg |= ((reg>>i) & 1)<<n;
n++;
}
return evenReg;
}
int main() {
uint32_t reg;
scanf("%u", ®);
printf("%u", extract_even_bits(reg));
return 0;
}
shift the even positions of the register to position 0 and extract.
Next thing is to put the extracted bit in the required position in even register.
Input
85
Expected Output
15