
Exclusive or, exclusive disjunction, exclusive alternation, logical non-equivalence, or
logical inequality is a
logical operator
In logic, a logical connective (also called a logical operator, sentential connective, or sentential operator) is a logical constant. Connectives can be used to connect logical formulas. For instance in the syntax of propositional logic, the ...
whose negation is the
logical biconditional
In logic and mathematics, the logical biconditional, also known as material biconditional or equivalence or bidirectional implication or biimplication or bientailment, is the logical connective used to conjoin two statements P and Q to form th ...
. With two inputs, XOR is true if and only if the inputs differ (one is true, one is false). With multiple inputs, XOR is true if and only if the number of true inputs is
odd.
It gains the name "exclusive or" because the meaning of "or" is ambiguous when both
operand
In mathematics, an operand is the object of a mathematical operation, i.e., it is the object or quantity that is operated on.
Unknown operands in equalities of expressions can be found by equation solving.
Example
The following arithmetic expres ...
s are true. XOR ''excludes'' that case. Some informal ways of describing XOR are "one or the other but not both", "either one or the other", and "A or B, but not A and B".
It is
symbolized by the prefix operator
[ Translated as ] and by the
infix operators XOR (, , or ), EOR, EXOR,
,
,
,
⩛,
,
, and
.
Definition

The
truth table
A truth table is a mathematical table used in logic—specifically in connection with Boolean algebra, Boolean functions, and propositional calculus—which sets out the functional values of logical expressions on each of their functional arg ...
of
shows that it outputs true whenever the inputs differ:
Equivalences, elimination, and introduction
Exclusive disjunction essentially means 'either one, but not both nor none'. In other words, the statement is true
if and only if
In logic and related fields such as mathematics and philosophy, "if and only if" (often shortened as "iff") is paraphrased by the biconditional, a logical connective between statements. The biconditional is true in two cases, where either bo ...
one is true and the other is false. For example, if two horses are racing, then one of the two will win the race, but not both of them. The exclusive disjunction
, also denoted by
or
, can be expressed in terms of the
logical conjunction
In logic, mathematics and linguistics, ''and'' (\wedge) is the Truth function, truth-functional operator of conjunction or logical conjunction. The logical connective of this operator is typically represented as \wedge or \& or K (prefix) or ...
("logical and",
), the
disjunction
In logic, disjunction (also known as logical disjunction, logical or, logical addition, or inclusive disjunction) is a logical connective typically notated as \lor and read aloud as "or". For instance, the English language sentence "it is ...
("logical or",
), and the
negation
In logic, negation, also called the logical not or logical complement, is an operation (mathematics), operation that takes a Proposition (mathematics), proposition P to another proposition "not P", written \neg P, \mathord P, P^\prime or \over ...
(
) as follows:
:
The exclusive disjunction
can also be expressed in the following way:
:
This representation of XOR may be found useful when constructing a circuit or network, because it has only one
operation and small number of
and
operations. A proof of this identity is given below:
:
It is sometimes useful to write
in the following way:
:
or:
:
This equivalence can be established by applying
De Morgan's laws
In propositional calculus, propositional logic and Boolean algebra, De Morgan's laws, also known as De Morgan's theorem, are a pair of transformation rules that are both Validity (logic), valid rule of inference, rules of inference. They are nam ...
twice to the fourth line of the above proof.
The exclusive or is also equivalent to the negation of a
logical biconditional
In logic and mathematics, the logical biconditional, also known as material biconditional or equivalence or bidirectional implication or biimplication or bientailment, is the logical connective used to conjoin two statements P and Q to form th ...
, by the rules of material implication (a
material conditional
The material conditional (also known as material implication) is a binary operation commonly used in logic. When the conditional symbol \to is interpreted as material implication, a formula P \to Q is true unless P is true and Q is false.
M ...
is equivalent to the disjunction of the negation of its
antecedent and its consequence) and
material equivalence.
In summary, we have, in mathematical and in engineering notation:
:
Negation of the operator
By applying the spirit of
De Morgan's laws
In propositional calculus, propositional logic and Boolean algebra, De Morgan's laws, also known as De Morgan's theorem, are a pair of transformation rules that are both Validity (logic), valid rule of inference, rules of inference. They are nam ...
, we get:
Relation to modern algebra
Although the
operators (
conjunction) and
(
disjunction
In logic, disjunction (also known as logical disjunction, logical or, logical addition, or inclusive disjunction) is a logical connective typically notated as \lor and read aloud as "or". For instance, the English language sentence "it is ...
) are very useful in logic systems, they fail a more generalizable structure in the following way:
The systems
and
are
monoid
In abstract algebra, a monoid is a set equipped with an associative binary operation and an identity element. For example, the nonnegative integers with addition form a monoid, the identity element being .
Monoids are semigroups with identity ...
s, but neither is a
group. This unfortunately prevents the combination of these two systems into larger structures, such as a
mathematical ring.
However, the system using exclusive or
''is'' an
abelian group
In mathematics, an abelian group, also called a commutative group, is a group in which the result of applying the group operation to two group elements does not depend on the order in which they are written. That is, the group operation is commu ...
. The combination of operators
and
over elements
produce the well-known
two-element field . This field can represent any logic obtainable with the system
and has the added benefit of the arsenal of algebraic analysis tools for fields.
More specifically, if one associates
with 0 and
with 1, one can interpret the logical "AND" operation as multiplication on
and the "XOR" operation as addition on
:
:
The description of a
Boolean function
In mathematics, a Boolean function is a function whose arguments and result assume values from a two-element set (usually , or ). Alternative names are switching function, used especially in older computer science literature, and truth functi ...
as a
polynomial
In mathematics, a polynomial is a Expression (mathematics), mathematical expression consisting of indeterminate (variable), indeterminates (also called variable (mathematics), variables) and coefficients, that involves only the operations of addit ...
in
, using this basis, is called the function's
algebraic normal form.
Exclusive or in natural language
Disjunction is often understood exclusively in
natural language
A natural language or ordinary language is a language that occurs naturally in a human community by a process of use, repetition, and change. It can take different forms, typically either a spoken language or a sign language. Natural languages ...
s. In English, the disjunctive word "or" is often understood exclusively, particularly when used with the particle "either". The English example below would normally be understood in conversation as implying that Mary is not both a singer and a poet.
:1. Mary is a singer or a poet.
However, disjunction can also be understood inclusively, even in combination with "either". For instance, the first example below shows that "either" can be
felicitously used in combination with an outright statement that both disjuncts are true. The second example shows that the exclusive inference vanishes away under
downward entailing In linguistics, linguistic semantics, a downward entailing (DE) propositional operator is one that constrains the meaning of an expression to a lower number or degree than would be possible without the expression. For example, "not," "nobody," "few ...
contexts. If disjunction were understood as exclusive in this example, it would leave open the possibility that some people ate both rice and beans.
:2. Mary is either a singer or a poet or both.
:3. Nobody ate either rice or beans.
Examples such as the above have motivated analyses of the exclusivity inference as
pragmatic conversational implicatures calculated on the basis of an inclusive
semantics
Semantics is the study of linguistic Meaning (philosophy), meaning. It examines what meaning is, how words get their meaning, and how the meaning of a complex expression depends on its parts. Part of this process involves the distinction betwee ...
. Implicatures are typically
cancellable and do not arise in downward entailing contexts if their calculation depends on the
Maxim of Quantity. However, some researchers have treated exclusivity as a bona fide semantic
entailment
Logical consequence (also entailment or logical implication) is a fundamental concept in logic which describes the relationship between statements that hold true when one statement logically ''follows from'' one or more statements. A valid l ...
and proposed nonclassical logics which would validate it.
This behavior of English "or" is also found in other languages. However, many languages have disjunctive constructions which are robustly exclusive such as French ''soit... soit''.
Alternative symbols
The symbol used for exclusive disjunction varies from one field of application to the next, and even depends on the properties being emphasized in a given context of discussion. In addition to the abbreviation "XOR", any of the following symbols may also be seen:
*
was used by
George Boole
George Boole ( ; 2 November 1815 – 8 December 1864) was a largely self-taught English mathematician, philosopher and logician, most of whose short career was spent as the first professor of mathematics at Queen's College, Cork in Ireland. H ...
in 1847.
Although Boole used
mainly on classes, he also considered the case that
are propositions in
, and at the time
is a connective. Furthermore, Boole used it exclusively. Although such use does not show the relationship between inclusive disjunction (for which
is almost fixedly used nowadays) and exclusive disjunction, and may also bring about confusions with its other uses, some classical and modern textbooks still keep such use.
*
was used by
Christine Ladd-Franklin in 1883.
Strictly speaking, Ladd used
to express "
is-not
" or "No
is
", i.e., used
as exclusions, while implicitly
has the meaning of exclusive disjunction since the article is titled as "On the Algebra of Logic".
*
, denoting the negation of
equivalence, was used by
Ernst Schröder in 1890,
[ Reprinted by Thoemmes Press in 2000.] Although the usage of
as equivalence could be dated back to
George Boole
George Boole ( ; 2 November 1815 – 8 December 1864) was a largely self-taught English mathematician, philosopher and logician, most of whose short career was spent as the first professor of mathematics at Queen's College, Cork in Ireland. H ...
in 1847,
during the 40 years after Boole, his followers, such as
Charles Sanders Peirce
Charles Sanders Peirce ( ; September 10, 1839 – April 19, 1914) was an American scientist, mathematician, logician, and philosopher who is sometimes known as "the father of pragmatism". According to philosopher Paul Weiss (philosopher), Paul ...
,
Hugh MacColl,
Giuseppe Peano
Giuseppe Peano (; ; 27 August 1858 – 20 April 1932) was an Italian mathematician and glottologist. The author of over 200 books and papers, he was a founder of mathematical logic and set theory, to which he contributed much Mathematical notati ...
and so on, did not use
as non-equivalence literally which is possibly because it could be defined from negation and equivalence easily.
*
was used by
Giuseppe Peano
Giuseppe Peano (; ; 27 August 1858 – 20 April 1932) was an Italian mathematician and glottologist. The author of over 200 books and papers, he was a founder of mathematical logic and set theory, to which he contributed much Mathematical notati ...
in 1894: "
. The sign
corresponds to Latin ''aut''; the sign
to ''vel''."
[ Reprinted in ] Note that the Latin word "aut" means "exclusive or" and "vel" means "inclusive or", and that Peano use
as inclusive disjunction.
*
was used by Izrail Solomonovich Gradshtein (Израиль Соломонович Градштейн) in 1936.
[ Translated as ]
*
was used by
Claude Shannon
Claude Elwood Shannon (April 30, 1916 – February 24, 2001) was an American mathematician, electrical engineer, computer scientist, cryptographer and inventor known as the "father of information theory" and the man who laid the foundations of th ...
in 1938. Shannon borrowed the symbol as exclusive disjunction from
Edward Vermilye Huntington
Edward Vermilye Huntington (April 26, 1874November 25, 1952) was an American mathematician.
Biography
Huntington was awarded the B.A. and the M.A. by Harvard University in 1895 and 1897, respectively. After two years' teaching at Williams College ...
in 1904.
Huntington borrowed the symbol from
Gottfried Wilhelm Leibniz
Gottfried Wilhelm Leibniz (or Leibnitz; – 14 November 1716) was a German polymath active as a mathematician, philosopher, scientist and diplomat who is credited, alongside Sir Isaac Newton, with the creation of calculus in addition to ...
in 1890 (the original date is not definitely known, but almost certainly it is written after 1685; and 1890 is the publishing time). While both Huntington in 1904 and Leibniz in 1890 used the symbol as an algebraic operation. Furthermore, Huntington in 1904 used the symbol as inclusive disjunction (logical sum) too, and in 1933 used
as inclusive disjunction.
*
, also denoting the negation of
equivalence, was used by
Alonzo Church
Alonzo Church (June 14, 1903 – August 11, 1995) was an American computer scientist, mathematician, logician, and philosopher who made major contributions to mathematical logic and the foundations of theoretical computer science. He is bes ...
in 1944.
*
(as a
prefix operator,
) was used by
Józef Maria Bocheński
Józef Maria Bocheński or Innocentius Bochenski (30 August 1902 – 8 February 1995) was a Polish Dominican, logician and philosopher.
Biography
Bocheński was born on 30 August 1902 in Czuszów, then part of the Russian Empire, to a fami ...
in 1949.
Somebody
may mistake that it is
Jan Łukasiewicz
Jan Łukasiewicz (; 21 December 1878 – 13 February 1956) was a Polish logician and philosopher who is best known for Polish notation and Łukasiewicz logic. His work centred on philosophical logic, mathematical logic and history of logi ...
who is the first to use
for exclusive disjunction (it seems that the mistake spreads widely), while neither in 1929
nor in other works did Łukasiewicz make such use. In fact, in 1949 Bocheński introduced a system of
Polish notation
Polish notation (PN), also known as normal Polish notation (NPN), Łukasiewicz notation, Warsaw notation, Polish prefix notation, Eastern Notation or simply prefix notation, is a mathematical notation in which Operation (mathematics), operator ...
that names all 16 binary
connectives
In logic, a logical connective (also called a logical operator, sentential connective, or sentential operator) is a logical constant. Connectives can be used to connect logical formulas. For instance in the syntax of propositional logic, th ...
of classical logic which is a compatible extension of the notation of Łukasiewicz in 1929, and in which
for exclusive disjunction appeared at the first time. Bocheński's usage of
as exclusive disjunction has no relationship with the Polish "alternatywa rozłączna" of "exclusive or" and is an accident for which see the table on page 16 of the book in 1949.
*
^, the
caret
Caret () is the name used familiarly for the character provided on most QWERTY keyboards by typing . The symbol has a variety of uses in programming and mathematics. The name "caret" arose from its visual similarity to the original proofre ...
, has been used in several
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
s to denote the
bitwise exclusive or operator, beginning with
C and also including
C++,
C#,
D,
Java
Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
,
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Though Perl is not officially an acronym, there are various backronyms in use, including "Practical Extraction and Reporting Language".
Perl was developed ...
,
Ruby
Ruby is a pinkish-red-to-blood-red-colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sapph ...
,
PHP and
Python.
* The
symmetric difference
In mathematics, the symmetric difference of two sets, also known as the disjunctive union and set sum, is the set of elements which are in either of the sets, but not in their intersection. For example, the symmetric difference of the sets \ and ...
of two sets
and
, which may be interpreted as their elementwise exclusive or, has variously been denoted as
,
, or
.
Properties
If using
binary values for true (1) and false (0), then ''exclusive or'' works exactly like
addition
Addition (usually signified by the Plus and minus signs#Plus sign, plus symbol, +) is one of the four basic Operation (mathematics), operations of arithmetic, the other three being subtraction, multiplication, and Division (mathematics), divis ...
modulo
In computing and mathematics, the modulo operation returns the remainder or signed remainder of a division, after one number is divided by another, the latter being called the '' modulus'' of the operation.
Given two positive numbers and , mo ...
2.
Computer science
Bitwise operation
Exclusive disjunction is often used for bitwise operations. Examples:
* 1 XOR 1 = 0
* 1 XOR 0 = 1
* 0 XOR 1 = 1
* 0 XOR 0 = 0
* XOR = (this is equivalent to addition without
carry)
As noted above, since exclusive disjunction is identical to addition modulo 2, the bitwise exclusive disjunction of two ''n''-bit strings is identical to the standard vector of addition in the
vector space
In mathematics and physics, a vector space (also called a linear space) is a set (mathematics), set whose elements, often called vector (mathematics and physics), ''vectors'', can be added together and multiplied ("scaled") by numbers called sc ...
.
In computer science, exclusive disjunction has several uses:
* It tells whether two bits are unequal.
* It is a controllable bit-flipper (the control input chooses whether or not to invert the data input).
* It tells whether there is an
odd number of 1 bits (
is true
if and only if
In logic and related fields such as mathematics and philosophy, "if and only if" (often shortened as "iff") is paraphrased by the biconditional, a logical connective between statements. The biconditional is true in two cases, where either bo ...
an odd number of the variables are true), which is equal to the
parity bit
A parity bit, or check bit, is a bit added to a string of binary code. Parity bits are a simple form of error detecting code. Parity bits are generally applied to the smallest units of a communication protocol, typically 8-bit octets (bytes) ...
returned by a
parity function.
In logical circuits, a simple
adder can be made with an
XOR gate
XOR gate (sometimes EOR, or EXOR and pronounced as Exclusive OR) is a digital logic gate that gives a true (1 or HIGH) output when the number of true inputs is odd. An XOR gate implements an exclusive disjunction, exclusive or (\nleftrightarrow) ...
to add the numbers, and a series of AND, OR and NOT gates to create the carry output.
On some computer architectures, it is more efficient to store a zero in a register by XOR-ing the register with itself (bits XOR-ed with themselves are always zero) than to load and store the value zero.
In
cryptography
Cryptography, or cryptology (from "hidden, secret"; and ''graphein'', "to write", or ''-logy, -logia'', "study", respectively), is the practice and study of techniques for secure communication in the presence of Adversary (cryptography), ...
, XOR is sometimes used as a simple, self-inverse mixing function, such as in
one-time pad
The one-time pad (OTP) is an encryption technique that cannot be Cryptanalysis, cracked in cryptography. It requires the use of a single-use pre-shared key that is larger than or equal to the size of the message being sent. In this technique, ...
or
Feistel network systems. XOR is also heavily used in block ciphers such as AES (Rijndael) or Serpent and in block cipher implementation (CBC, CFB, OFB or CTR).
In simple threshold-activated
artificial neural network
In machine learning, a neural network (also artificial neural network or neural net, abbreviated ANN or NN) is a computational model inspired by the structure and functions of biological neural networks.
A neural network consists of connected ...
s, modeling the XOR function requires a second layer because XOR is not a
linearly separable function.
Similarly, XOR can be used in generating
entropy pools for
hardware random number generator
In computing, a hardware random number generator (HRNG), true random number generator (TRNG), non-deterministic random bit generator (NRBG), or physical random number generator is a device that generates random numbers from a physical process c ...
s. The XOR operation preserves randomness, meaning that a random bit XORed with a non-random bit will result in a random bit. Multiple sources of potentially random data can be combined using XOR, and the unpredictability of the output is guaranteed to be at least as good as the best individual source.
XOR is used in
RAID
RAID (; redundant array of inexpensive disks or redundant array of independent disks) is a data storage virtualization technology that combines multiple physical Computer data storage, data storage components into one or more logical units for th ...
3–6 for creating parity information. For example, RAID can "back up" bytes and from two (or more) hard drives by XORing the just mentioned bytes, resulting in () and writing it to another drive. Under this method, if any one of the three hard drives are lost, the lost byte can be re-created by XORing bytes from the remaining drives. For instance, if the drive containing is lost, and can be XORed to recover the lost byte.
XOR is also used to detect an overflow in the result of a signed binary arithmetic operation. If the leftmost retained bit of the result is not the same as the infinite number of digits to the left, then that means overflow occurred. XORing those two bits will give a "1" if there is an overflow.
XOR can be used to swap two numeric variables in computers, using the
XOR swap algorithm; however this is regarded as more of a curiosity and not encouraged in practice.
XOR linked lists leverage XOR properties in order to save space to represent
doubly linked list data structures.
In
computer graphics
Computer graphics deals with generating images and art with the aid of computers. Computer graphics is a core technology in digital photography, film, video games, digital art, cell phone and computer displays, and many specialized applications. ...
, XOR-based drawing methods are often used to manage such items as
bounding boxes and
cursors on systems without
alpha channels or overlay planes.
Encodings
It is also called "not left-right arrow" (
\nleftrightarrow
) in
LaTeX
Latex is an emulsion (stable dispersion) of polymer microparticles in water. Latices are found in nature, but synthetic latices are common as well.
In nature, latex is found as a wikt:milky, milky fluid, which is present in 10% of all floweri ...
-based markdown (
). Apart from the ASCII codes, the operator is encoded at and , both in block
mathematical operators.
See also
Notes
External links
All About XORProofs of XOR properties and applications of XOR, CS103: Mathematical Foundations of Computing, Stanford University
{{Logical connectives
Dichotomies
Logical connectives
Semantics