## You are here

Homebitwise XOR

## Primary tabs

# bitwise XOR

Bitwise XOR or bitwise exclusive OR is a bit-level operation on two binary values which indicates which bits are set in only one value. For each position $i$, if the bit $d_{i}$ in one value is 1 and the other is 0, then $d_{i}$ of the result is 1, otherwise itâ€™s 0. If both input $d_{i}$ are 1, the output $d_{i}$ is 0. then For example, given 50 and 163 in two unsigned bytes, a bitwise XOR returns 145.

0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | |

XOR | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 1 |
---|---|---|---|---|---|---|---|---|

= | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 1 |

Given a Mersenne number of the form $2^{k}-1$ (where $k$ is the bit size of the data type in use, e.g., 8 for bytes, 16 for words, 32 for double words, etc.) and some smaller integer $n$, XORing that Mersenne number with $n$ has the same effect as performing a bitwise NOT on $n$. Or, given $m$ and $n$, XORing them has the same effect as $m-n$ (subject to some caveats about the sign bit, or if the values are unsigned, the effect is then the same as $|m-n|$). XORing two values that are the same gives 0.

## Mathematics Subject Classification

11A63*no label found*

- Forums
- Planetary Bugs
- HS/Secondary
- University/Tertiary
- Graduate/Advanced
- Industry/Practice
- Research Topics
- LaTeX help
- Math Comptetitions
- Math History
- Math Humor
- PlanetMath Comments
- PlanetMath System Updates and News
- PlanetMath help
- PlanetMath.ORG
- Strategic Communications Development
- The Math Pub
- Testing messages (ignore)

- Other useful stuff
- Corrections