Difficulty: Easy
Correct Answer: The ^ operator can be used to invert a bit.
Explanation:
Introduction / Context:
This question deals with the XOR (exclusive OR) bitwise operator in C#.
Given Data / Assumptions:
Concept / Approach:
XOR flips bits where the other operand has 1. This property allows toggling (inverting) selected bits.
Step-by-Step Solution:
Verification / Alternative check:
For bit toggle: value ^ 0xFF inverts all bits of value.
Why Other Options Are Wrong:
XOR does not always set ON or OFF; it toggles depending on mask. It is not used for bit testing directly.
Common Pitfalls:
Confusing XOR with OR. XOR is for toggling, not just turning bits ON.
Final Answer:
The ^ operator can be used to invert a bit.
Discussion & Comments