#include <stdio.h> #include <stdint.h> uint8_t extract_field(uint16_t reg) { // Your logic here return (reg>>4)&0x1F; } int main() { uint16_t reg; scanf("%hx", ®); printf("%u", extract_field(reg)); return 0; }
reg >>= 4; // Shift bits 4–8 to positions 0–4return reg & 0x1F; // Mask lower 5 bits to extract the field
Test Cases
Test Results
Input
0x01F0
Expected Output
31