2. Bit Toggle

Back To All Submissions
Previous Submission
Next Submission

Code

#include <stdio.h>

int toggleFifthBit(int n) {
    // Write your code here
    unsigned char bit5 = (n >> 5u) & 0x01;
    int res = n;

    if(bit5==0){
        res = res | (1<<5);
    }
    else
    {
        res = res & ~(1<<5);
    }
    return res;
}

int main() {
    int n;
    scanf("%d", &n);
    printf("%d", toggleFifthBit(n));
    return 0;
}

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote