Home >Backend Development >C++ >What does ^ mean in C language?
In C language, ^ is the exclusive OR (XOR) operator, which acts on two operands bitwise. For each bit, if both bits are 0 or both are 1, the result bit is 0; if one bit is 0 and the other bit is 1, the result bit is 1. Applications of the XOR operator include setting or clearing bits, swapping variables, checking parity, encryption, and bit masking operations.
The ^ symbol in C language
What is it?
In C language, ^ is the exclusive OR (XOR) operator.
How does it work?
The XOR operator acts on two operands and evaluates them bitwise. For each bit, if both bits are 0 or both are 1, the resulting bit is 0; if one bit is 0 and the other is 1, the resulting bit is 1.
Example
<code class="c">int a = 10; // 0b1010 int b = 15; // 0b1111 int result = a ^ b; // 0b0101</code>
In this case, the result is 5.
Applications
The XOR operator has many applications, including:
The above is the detailed content of What does ^ mean in C language?. For more information, please follow other related articles on the PHP Chinese website!