#include <stdio.h> int main() { unsigned char reg; int pos; scanf("%hhu %d", ®, &pos); unsigned char nibble; if (pos == 0) { // Lower nibble nibble = reg & 0x0F; } else { // Upper nibble nibble = (reg >> 4) & 0x0F; } printf("%d\n", nibble); return 0; }
Test Cases
Test Results
Input
170 0
Expected Output
10