Skip to main content
GameDev.net gamedev.net
🔒 Locked

a C question

Started by dinotoast Sep 1, 2003 at 10:50 PM 1 replies 550+ views
Original Post
dinotoast
dinotoast
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?
tortoise
tortoise

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]
dinotoast
dinotoast
thanks heaps!

i''ll remeber that for next time

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.