Interview Question

Software Engineer Interview Kansas City, MO

Flip a bit in a uint32 using C.

Answer

Interview Answer

3 Answers

0

If you don't know how to do this, you didn't go to computer science 101 class.

Interview Candidate on Mar 10, 2012
0

For those not familiar with C, I believe teh following should work:

//This is using the Exclusive Or(XOR) operator
unsigned flipBit ( unsigned x, unsigned bit )
{
    return x ^ (1UL << bit);4.
}

Anonymous on Aug 2, 2012
0

Reposted as I left a 4. in there that should not be.

For those not familiar with C, I believe the following should work:

//This is using the Exclusive Or(XOR) operator
unsigned flipBit ( unsigned x, unsigned bit )
{
    return x ^ (1UL << bit);
}

Anonymous on Aug 2, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.