1. Set or Clear a Specific Bit in a Register

Discussions3
Log in to post comments and replies.
You
GauthamShankar
GauthamShankarMar 04 2026
    if(mode==1){
        reg |= (1U<<pos);
    }
    else reg&=~(1U<<pos);
    return reg;
0
MohanKilari
MohanKilariDec 20 2025
#include <stdio.h>

unsigned char modifyBit(unsigned char reg, int pos, int mode) {
    // Write your code here
    if(mode == 1){
        reg |= (1<< pos);
    }
    else if(mode==0){
        reg&=~(1<<pos);
    }
    return reg;
}

int main() {
    unsigned char reg;
    int pos, mode;
    scanf("%hhu %d %d", &reg, &pos, &mode);
    printf("%d", modifyBit(reg, pos, mode));
    return 0;
}
0
VELMURUGANPMCT
VELMURUGANPMCTApr 28 2026

i dont understand 

 

-4