What is Bitwise XOR?
Bitwise XOR (exclusive OR) is a binary operation that takes two equal-length binary representations and performs the logical XOR operation on each pair of corresponding bits. The result in each position is 1 if only one of the two bits is 1 but will be 0 if both are 0 or both are 1.
The truth table for the XOR (exclusive OR) operation is as follows:
A | B | A XOR B |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
In this table, A and B are the variables, and A XOR B is the expression representing the logical XOR operation. The table shows all possible combinations of truth values for A and B, and the resulting truth value of A XOR B for each combination.
The XOR operation returns 1 (true) if the inputs are different, and 0 (false) if they are the same. This is why the output is 1 for the second and third rows, where A and B have different values, and 0 for the first and fourth rows, where A and B have the same value.
Bitwise XOR Operator in Programming
Bitwise XOR Operator is represented by the caret symbol (^). It is used to perform a bitwise XOR operation on the individual bits of two operands. The XOR operator returns 1 if the corresponding bits in the two operands are different, and 0 if they are the same.
Table of Content
- What is Bitwise XOR?
- Bitwise XOR operator:
- Bitwise XOR operator in C:
- Bitwise XOR operator in C++:
- Bitwise XOR operator in Java:
- Bitwise XOR operator in Python:
- Bitwise XOR operator in C#:
- Bitwise XOR operator in Javascript:
- Use Cases of Bitwise XOR Operator:
- Applications of Bitwise XOR Operator in Programming: