#include <stdio.h>
unsigned char modifyBit(unsigned char reg, int pos, int mode) {
if(mode ==1 ){
reg |= (1<<pos);
}
else{
reg &= ~(1 << 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;
}
A register in a microcontroller or CPU is a small piece of memory (usually 8, 16, or 32 bits) that controls hardware or stores status flags.
Each bit (0 or 1) inside the register often has a special meaning — turning on a feature, indicating a status, or controlling a pin.
0
to 1
(enabling that feature/flag).1
to 0
(disabling that feature/flag).1
or 0
.In embedded systems or low-level programming, many hardware devices are controlled by writing to their registers.
Input
10 3 1
Expected Output
10