All submissions

Code

#include <stdio.h>

int toggleFifthBit(int n) {
    
    // get the fifth bit by masking the n by 0b00100000
    unsigned char result = n&0b00100000;
    
    // check if the 5th bit is 1
    if(result>0)
    {
        // fli[ to 0
       n &= ~(1<<5);
    }

    else // 5th bit is 0
    {
        // flip to 1
        n|=(1<<5);
    }

    return n;

}

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

Solving Approach

 

 

 

Loading...

Input

8

Expected Output

40