• ### Announcements

#### Archived

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

# a C question

## 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 on other sites
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
thanks heaps!

i''ll remeber that for next time

• ### Forum Statistics

• Total Topics
628282
• Total Posts
2981812

• 9
• 10
• 11
• 17
• 15