Archived

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

a C question

Recommended Posts

dinotoast    122
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 on other sites
tortoise    122
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 on other sites
dinotoast    122
thanks heaps!

i''ll remeber that for next time