2. Bit Toggle

Back To All Submissions
Previous Submission
Next Submission

Code

#include <stdio.h>

int toggleFifthBit(int n) {
    n  = n^(1<<5);
    // Write your code here
    return n;
}

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

Solving Approach

  1. create a mask bit (1<<5) . ie 1 - 10 - 100 - 1000 - 10000 -100000
  2. xor with user input.

 

 

Was this helpful?
Upvote
Downvote