Interview Question

Mtech Interview(Student Candidate) Bangalore (India)

flip the 5th bit of register in c

Answer

Interview Answer

3 Answers

0

just read bitwise operators

Interview Candidate on Jun 7, 2012
0

#include<stdio.h>
#define NUM 10
int main()
{
        register int n=NUM;
        n=(1<<4)&n?(~(1<<4))&n:(1<<4)|n;
        printf("%d ",n);
        return 0;
}

Anonymous on Sep 17, 2012
0

#include<stdio.h>
#define NUM 10
int main()
{
        register int n=NUM;
        n^=(1<<4);
        printf("%d ",n);
        return 0;
}

Dinesh T on Apr 15, 2014

Add Answers or Comments

To comment on this, Sign In or Sign Up.