BitXor[n1,n2,…]
gives the bitwise XOR of the integers ni.
BitXor
BitXor[n1,n2,…]
gives the bitwise XOR of the integers ni.
Details
- Integer mathematical function, suitable for both symbolic and numerical manipulation.
- BitXor[n1,n2,…] yields the integer whose binary bit representation has ones at positions where an odd number of the binary bit representations of the ni have ones. »
- For negative integers BitXor assumes a two's complement representation.
- BitXor automatically threads over lists. »
Examples
open all close allBasic Examples (1)
Scope (4)
BitXor[3 ^ 100, 5 ^ 100]BitXor takes any number of arguments:
BitXor[3333, 5555, 7777, 9999]BitXor[-2, -3]Basic symbolic simplifications are done automatically:
BitXor[x, y, y, x]BitXor[1, 2, x]Applications (6)
Truth table for Xor:
Grid[Outer[BitXor, {1, 0}, {1, 0}]]ArrayPlot[Table[Boole[BitXor[i, j] == i + j], {i, 0, 63}, {j, 0, 63}]]This structure corresponds to the Sierpiński gasket:
SierpinskiMesh[5]Plot the BitXor of
with
:
ListLinePlot[Table[BitXor[i, i - 1], {i, 50}], PlotRange -> All]Plot the BitXor of
with
:
ListLinePlot[Table[BitXor[i, 2i], {i, 64}]]Plot the BitXor of
with
and
:
ListLinePlot[Table[BitXor[i, 2i, 3i], {i, 64}]]Generate a Gray code sequence [more info]:
Table[BitXor[i, Floor[i / 2]], {i, 16}]ListLinePlot[Table[BitXor[i, Floor[i / 2]], {i, 64}]]Bitwise version of rule 60 cellular automaton:
ArrayPlot[IntegerDigits[NestList[BitXor[#, 2#]&, 1, 63], 2]]Properties & Relations (4)
-1 corresponds to having all bits on:
BitXor[-1, x]Even numbers of identical arguments give 0:
BitXor[x, x, x, x]Odd numbers of identical arguments give the argument:
BitXor[x, x, x, x, x]BitXor automatically threads over lists:
BitXor[5, Range[10]]BitXor[y, x]Neat Examples (3)
Plotting BitXor[x,y] in the plane shows a nested pattern of squares:
ArrayPlot[Array[BitXor, {63, 63}]]Plotting in three dimensions reveals a fractal structure:
Graphics3D[Table[Cuboid[{i, j, BitXor[i, j]}], {i, 31}, {j, 31}]]This structure corresponds to the Sierpiński sponge:
SierpinskiMesh[5, 3]"Munching squares" [more info]:
Table[ArrayPlot[Table[Boole[BitXor[i, j] < t], {i, 7}, {j, 7}], ImageSize -> 50], {t, 0, 8}]See Also
BitAnd BitOr BitNot Xor IntegerDigits CellularAutomaton HammingDistance SequenceAlignment
Function Repository: BitStringNullSpace BitStringRowReduce BitBooleanFunction
Tech Notes
Related Guides
Related Links
History
Introduced in 1999 (4.0)
Text
Wolfram Research (1999), BitXor, Wolfram Language function, https://reference.wolfram.com/language/ref/BitXor.html.
CMS
Wolfram Language. 1999. "BitXor." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/BitXor.html.
APA
Wolfram Language. (1999). BitXor. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/BitXor.html
BibTeX
@misc{reference.wolfram_2026_bitxor, author="Wolfram Research", title="{BitXor}", year="1999", howpublished="\url{https://reference.wolfram.com/language/ref/BitXor.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_bitxor, organization={Wolfram Research}, title={BitXor}, year={1999}, url={https://reference.wolfram.com/language/ref/BitXor.html}, note=[Accessed: 13-June-2026]}