Set or Clear a Specific Bit in a Register

Code

#include <stdio.h>


int main() {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if(c == 1)
    {
        a |= (1 << b);
        printf("%d", a);
    }
    else if(c == 0)
    {
        a &= ~(1 << b);
        printf("%d", a);
    }
}

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

10 3 1

Expected Output

10