All submissions

Code

#include <stdio.h>

int toggleFifthBit(int n) {
    return n ^ (1 << 5);
}

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

Solving Approach

XOR (exclusive OR) results in 1 if bits are different (1 0 or 0 1) and 0 if bits are equal (0 0 or 1 1). So in our case if number is 00001010 and our mask is 00100000 (5th bit values are differ), result is 1 and 00101010. And if number is 00101010 and our mask is 00100000 (5th bit values are equal), result is 0 and 00001010.

 

 

Loading...

Input

8

Expected Output

40