#include <stdio.h> #define LOWER 0 #define HIGHER 1 #define LOWER_NIBBLE 4 unsigned char extractNibble(unsigned char reg, int pos) { // Write your code here if (pos == HIGHER) return reg >> LOWER_NIBBLE; else if (pos == LOWER) return reg & 0x0F; else return 0; } int main() { unsigned char reg; int pos; scanf("%hhu %d", ®, &pos); printf("%d", extractNibble(reg, pos)); return 0; }
Test Cases
Test Results
Input
170 0
Expected Output
10