#include <stdio.h> #include <stdint.h> #define mask 0x0F uint8_t extracNibble(uint8_t reg, int pos){ if (pos == 0){ return reg &= mask; } else if(pos == 1){ return reg = (reg >> 4) &mask; } } int main() { uint8_t pos; uint8_t reg; scanf("%hhu %hhu", ®, &pos); printf("%d", extracNibble(reg, pos)); return 0; }
Test Cases
Test Results
Input
170 0
Expected Output
10