Code

#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

1.set the mask for 5 th bit which was mentioned as constraint 

2. use X-OR but ^ for toggle , how it works: same value = 0, different value = 1.

3.by using it we can toggle the bit

 

 

Upvote
Downvote
Loading...

Input

8

Expected Output

40