2. Bit Toggle

Back To All Submissions
Previous Submission
Next Submission

Code

#include <stdio.h>
int main() {
    int n;
    scanf("%d", &n);
    printf("%d", n ^ (1 << 5));
    return 0;
}

Solving Approach

Use XOR with bitmask (1 << 5) to toggle the 5th bit while preserving all other bits

 

 

Was this helpful?
Upvote
Downvote