All submissions

Extract the Nibble from an 8-bit Register

Code

#include<stdio.h>
unsigned char nibble(unsigned char reg , int choice)
{
    if(choice ==0){  //is choice 0 by user then its nee  bit 
    return reg & 0x0F;//lower (0-4)
    }

    else{
        return (reg>>4) & 0x0F;
    }
    
}
int main()
{  
    unsigned char reg;
    int ch;
    //printf("enter reg and choice");
    scanf("%hhu %d" ,&reg ,&ch);
    printf("%d", nibble(reg,ch));
    return 0;
}

Solving Approach

 

 

 

Loading...

Input

170 0

Expected Output

10