Set the Bit in an 8-bit Register

Code

#include<stdio.h>

unsigned char modfy(unsigned char reg, unsigned char  pos)
{
    unsigned char mask=1<<pos;
    return mask | reg;
}

int main()
{
    unsigned char reg, pos;
    scanf("%hhu %hhu",&reg, &pos);
    printf("%u",modfy(reg,pos));
    return 0;
}

Solving Approach
 

 

 

Upvote
Downvote
Loading...

Input

5 1

Expected Output

7