#include <stdio.h>
int toggleFifthBit(int n) {
// Write your code here
n ^= (1 << 5);
return n;
}
int main() {
int n;
scanf("%d", &n);
printf("%d", toggleFifthBit(n));
return 0;
}
Solving Approach
Toggling the fifth bit is simply applying the XOR operator bitwise to the 5th bit with the bit value of 1. Truth table of XOR that matters: 0 XOR 1 = 1 1 XOR 1 = 0