#include <stdio.h>
unsigned char modifyBit(unsigned char reg, int pos, int mode) {
// Write your code here
if(mode==1)
reg|=(1U<<pos);
else
reg &= ~(1U<<pos);
return reg;
}
int main() {
unsigned char reg;
int pos, mode;
scanf("%hhu %d %d", ®, &pos, &mode);
printf("%d", modifyBit(reg, pos, mode));
return 0;
}Create a Mask: A mask is generated to isolate the target bit at position pos. This is done by shifting the number 1 to the left by pos places (1U << pos). The result is a number with a 1 only at the target bit position and 0s everywhere else.
Check the Mode:
Input
10 3 1
Expected Output
10