#include <stdio.h> #include <stdint.h> #define START_BIT 4 #define END_BIT 8 #define BITS_LEN 5 uint8_t extract_field(uint16_t reg) { // Your logic here uint16_t mask = ((1 << BITS_LEN) - 1) << START_BIT; uint8_t ext_bit = (reg & mask) >> START_BIT; return ext_bit; } int main() { uint16_t reg; scanf("%hx", ®); printf("%u", extract_field(reg)); return 0; }
Test Cases
Test Results
Input
0x01F0
Expected Output
31