Bitwise Manipulation Functions

Viewed 1547

Possible Duplicate:
How do you set, clear and toggle a single bit in C?

I'm studying for an upcoming final and I want to verify some questions from the study guide.

Some context:

  • The Set() function sets a bit in a byte to 1

  • The Unset() function sets a bit in a byte to 0

  • The Flip() function "flips" the bit to the opposite of what it is

So some kid in our class took it upon himself to answer the study guide questions but I've already found some errors, and these answers sound fishy. Here's what he said:

Which operation is used for the Set? the or operator |

Which operation is used for the Unset? Xor operator ^ Done twice

Which operation is used for the Flip? Xor operator ^

Are these the correct bitwise operators to implement in the functions I've described above?

4 Answers
Related