Code

#include <stdio.h>

int toggleFifthBit(int n) {
    // 5th bit in 0 indexed is to bit shift by 5
    n ^= (1<<5);
    return n;
}

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

Solving Approach

 

xoring by 1 toggles the bit by flipping 1 to 0 and 0 to 1

 

Upvote
Downvote
Loading...

Input

8

Expected Output

40