# 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.

Title | bitwise XOR |
---|---|

Canonical name | BitwiseXOR |

Date of creation | 2013-03-22 17:02:52 |

Last modified on | 2013-03-22 17:02:52 |

Owner | PrimeFan (13766) |

Last modified by | PrimeFan (13766) |

Numerical id | 4 |

Author | PrimeFan (13766) |

Entry type | Definition |

Classification | msc 11A63 |

Related topic | BitwiseAND |

Related topic | BitwiseOR |

Related topic | BitwiseNOT |