All submissions

Extract Bit Field from 16-bit Register

Code

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

#define FIELD_MASK ((1U<<5U)-1U)
#define FIELD_POS (4)
uint8_t extract_field(uint16_t reg) {
    // Your logic here
    uint8_t ret_val = (uint8_t)((reg>>FIELD_POS)&FIELD_MASK);
    return ret_val;
}

int main() {
    uint16_t reg;
    scanf("%hx", &reg);
    printf("%u", extract_field(reg));
    return 0;
}

Solving Approach

 

 

 

Loading...

Input

0x01F0

Expected Output

31