2. Bit Toggle

Back To All Submissions
Previous Submission
Next Submission

Code

#include <stdio.h>

int toggleFifthBit(int n) {
    // Write your code here
    int num = 0x20;
    return (num ^ n);
}

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

Solving Approach

 

used xor for toggling the bit create an offset for the desired number and xor with it result will be toggled number of offset and given number

 

Was this helpful?
Upvote
Downvote