• Advertisement

Archived

This topic is now archived and is closed to further replies.

a C question

This topic is 5288 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I got this question in an entrance test for a game programming skool, and I was extremely stuck on how to do it... Write a function to flip bit 7 of a char (eg. If I have the value 35 – which in binary is: 00100011 and I flip bit 7 it should become 10100011 – or 163 and if I flip bit 7 of 163 it would become 35). any ideas?

Share this post


Link to post
Share on other sites
Advertisement

unsigned char flip(unsigned char c) {
static unsigned char a = 1 << 7;

return c ^ a;
}


that's exclusive or, not used too often.

[edited by - tortoise on September 1, 2003 12:06:37 AM]

Share this post


Link to post
Share on other sites

  • Advertisement