#include <stdio.h>
int toggleFifthBit(int n) {
// Write your code here
return n = n ^ 1<<5;
}
int main() {
int n;
scanf("%d", &n);
printf("%d", toggleFifthBit(n));
return 0;
}
Solving Approach
✅ Bit Toggle – Small & Compact Solving Approach
1️⃣ Understand the target bit
0-based indexing
5th bit → position = 5
Mask value = 1 << 5
2️⃣ Create the bit mask
1 << 5
This produces:
00100000 (decimal 32)
3️⃣ Use XOR to toggle
Rule:
XOR with 1 → flips the bit
XOR with 0 → unchanged
So:
N = N ^ (1 << 5);
4️⃣ Return/Print result
That’s it.
💡 Final Logic in One Line
result = N ^ (1 << 5);
✔ Simple ✔ No condition ✔ Constant time ✔ Embedded-safe