Code

#include <stdio.h>

int toggleFifthBit(int n) {
    // Create a mask with only the 5th bit set (0-based index)
    int mask = 1 << 5;   // 1 shifted left by 5 \u2192 0b00100000 (decimal 32)

    // XOR with mask toggles the 5th bit
    return n ^ mask;
}

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

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

8

Expected Output

40