Code

#include <stdio.h>

int toggleFifthBit(int n) {
    int position = 5;        // 5th bit (0-based index)
    int mask = 1 << position; // Create a mask: 00100000 (32)
    return n ^ mask;          // XOR toggles the bit
}

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

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

8

Expected Output

40