All submissions

Code

#include <stdio.h>

// Mask for fifth bit
#define BIT_MASK (1 << 5)

int toggleFifthBit(int n) {
    
     
    // Operations belowe can be compacted in a single return statement
    /*
    int value = n & BIT_MASK;
    // Toggle the bit (the last & operation is required, because after the toggle all 0 bits from the mask will become a 1) 
    value = (~(n & BIT_MASK)) & BIT_MASK;
    // Clear the fifth bit 
    n &= ~BIT_MASK;
    // Set the toggled bit
    n |= value;
    */
    return ((n & ~BIT_MASK) | (~(n & BIT_MASK) & BIT_MASK));
}

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

Solving Approach

 

 

 

Loading...

Input

8

Expected Output

40