Code

#include <stdio.h>

int toggleFifthBit(int n) {
    // Write your code here

    // check if bit is set:
    if ((1 << 5) & n) {
        // Bit is set, so clear it
        n &= ~(1 << 5);
    } else {
        // Bit is clear, so set it
        n |= (1 << 5);
    }
    return n;
}

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

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

8

Expected Output

40