Hubbry Logo
Exclusive orExclusive orMain
Open search
Exclusive or
Community hub
Exclusive or
logo
8 pages, 0 posts
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
Contribute something
Exclusive or
Exclusive or
from Wikipedia
Exclusive disjunction
XOR
Venn diagram of Exclusive disjunction
Truth table
Logic gate
Normal forms
Disjunctive
Conjunctive
Zhegalkin polynomial
Post's lattices
0-preservingyes
1-preservingno
Monotoneno
Affineyes
Self-dualno
Venn diagram of

Exclusive or, exclusive disjunction, exclusive alternation, logical non-equivalence, or logical inequality is a logical operator whose negation is the logical biconditional. 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.[1]

It gains the name "exclusive or" because the meaning of "or" is ambiguous when both operands 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 [2]: 16  and by the infix operators XOR (/ˌɛks ˈɔːr/, /ˌɛks ˈɔː/, /ˈksɔːr/ or /ˈksɔː/), EOR, EXOR, , , , , , , and .

Definition

[edit]
Each row of this binary Walsh matrix is the truth table of the variadic XOR of the arguments shown on the left. E.g. row AB corresponds to the 2-circle, and row ABC to the 3-circle Venn diagram shown above. (As in the Venn diagrams, white is false, and red is true.)

The truth table of shows that it outputs true whenever the inputs differ:

FFF
FTT
TFT
TTF

Equivalences, elimination, and introduction

[edit]

Exclusive disjunction essentially means 'either one, but not both nor none'. In other words, the statement is true if and only if 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 ("logical and", ), the disjunction ("logical or", ), and the negation () 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 twice to the fourth line of the above proof.

The exclusive or is also equivalent to the negation of a logical biconditional, by the rules of material implication (a material conditional 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

[edit]

By applying the spirit of De Morgan's laws, we get:

Relation to modern algebra

[edit]

Although the operators (conjunction) and (disjunction) are very useful in logic systems, they fail a more generalizable structure in the following way:

The systems and are monoids, 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. 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 as a polynomial in , using this basis, is called the function's algebraic normal form.[3]

Exclusive or in natural language

[edit]

Disjunction is often understood exclusively in natural languages. 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.[4][5]

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 contexts. If disjunction were understood as exclusive in this example, it would leave open the possibility that some people ate both rice and beans.[4]

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. 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 and proposed nonclassical logics which would validate it.[4]

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.[4]

Alternative symbols

[edit]

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 in 1847.[6] 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.[7][8]
  • was used by Christine Ladd-Franklin in 1883.[9] 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,[10]: 307  Although the usage of as equivalence could be dated back to George Boole in 1847,[6] during the 40 years after Boole, his followers, such as Charles Sanders Peirce, Hugh MacColl, Giuseppe Peano 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 in 1894: ". The sign corresponds to Latin aut; the sign to vel."[11]: 10  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.[12]: 76 
  • was used by Claude Shannon in 1938.[13] Shannon borrowed the symbol as exclusive disjunction from Edward Vermilye Huntington in 1904.[14] Huntington borrowed the symbol from Gottfried Wilhelm Leibniz in 1890 (the original date is not definitely known, but almost certainly it is written after 1685; and 1890 is the publishing time).[15] 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.[16]
  • , also denoting the negation of equivalence, was used by Alonzo Church in 1944.[17]
  • (as a prefix operator, ) was used by Józef Maria Bocheński in 1949.[2]: 16  Somebody[18] may mistake that it is Jan Łukasiewicz who is the first to use for exclusive disjunction (it seems that the mistake spreads widely), while neither in 1929[19] nor in other works did Łukasiewicz make such use. In fact, in 1949 Bocheński introduced a system of Polish notation that names all 16 binary connectives 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, has been used in several programming languages to denote the bitwise exclusive or operator, beginning with C[20] and also including C++, C#, D, Java, Perl, Ruby, PHP, Python and Rust.
  • The symmetric difference of two sets and , which may be interpreted as their elementwise exclusive or, has variously been denoted as , , or .[21]

Properties

[edit]
Commutativity: yes
        
        
Associativity: yes
        
                 
Distributivity:
The exclusive or does not distribute over any binary function (not even itself), but logical conjunction distributes over exclusive or. (Conjunction and exclusive or form the multiplication and addition operations of a field GF(2), and as in any field they obey the distributive law.)
Idempotency: no
                 
                 
Monotonicity: no
        
                 
Truth-preserving: no
When all inputs are true, the output is not true.
        
        
Falsehood-preserving: yes
When all inputs are false, the output is false.
        
        
Walsh spectrum: (2,0,0,−2)
Non-linearity: 0
The function is linear.
Involution:
Exclusive or with one specified input, as a function of the other input, is an involution or self-inverse function; applying it twice leaves the variable input unchanged.
        
        

If using binary values for true (1) and false (0), then exclusive or works exactly like addition modulo 2.

Computer science

[edit]
Traditional symbolic representation of an XOR logic gate

Bitwise operation

[edit]
Nimber addition is the exclusive or of nonnegative integers in binary representation. This is also the vector addition in .

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
  • 11102 XOR 10012 = 01112 (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 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 an odd number of the variables are true), which is equal to the parity bit returned by a parity function.

In logical circuits, a simple adder can be made with an XOR gate 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, XOR is sometimes used as a simple, self-inverse mixing function, such as in one-time pad or Feistel network systems.[citation needed] 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 networks, 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 generators. 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.[22]

XOR is used in RAID 3–6 for creating parity information. For example, RAID can "back up" bytes 100111002 and 011011002 from two (or more) hard drives by XORing the just mentioned bytes, resulting in (111100002) 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 011011002 is lost, 100111002 and 111100002 can be XORed to recover the lost byte.[23]

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, 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

[edit]

It is also called "not left-right arrow" (\nleftrightarrow) in LaTeX-based markdown (). Apart from the ASCII codes, the operator is encoded at U+22BB XOR (⊻) and U+2295 CIRCLED PLUS (⊕, ⊕), both in block mathematical operators.

See also

[edit]

Notes

[edit]
[edit]
Revisions and contributorsEdit on WikipediaRead on Wikipedia
from Grokipedia
The exclusive or, commonly abbreviated as XOR, is a binary logical operation in that outputs true (1) exactly one of its two is true, and false (0) otherwise. This operation is distinct from the inclusive OR, as it excludes the case where both are true. XOR is symbolized by the ⊕ operator in and is implemented as a fundamental in digital circuits. The truth table for the XOR operation with two inputs, A and B, is as follows:
ABA ⊕ B
000
011
101
110
This table illustrates that the output is 1 precisely when the inputs differ. For multiple inputs, XOR generalizes to produce 1 if there is an odd number of 1s among them; the operation is associative and commutative. In programming languages like C++, , and Python, the bitwise XOR is denoted by the (^) and operates on integers bit by bit. XOR plays a critical role in various fields, particularly in and communications, with applications including error detection, , and . Its properties, such as self-invertibility (where XORing a value with itself yields 0, as shown in the truth table), support uses in algorithms like hashing and checksums.

Fundamentals

Definition

The exclusive or (XOR), also known as exclusive disjunction, is a fundamental binary logical operator in propositional logic and that evaluates to true if exactly one of its two inputs is true and false otherwise. For propositions pp and qq, the statement pqp \oplus q holds true precisely when pp and qq have differing truth values—one is true and the other false—making it distinct from the inclusive or, which allows both inputs to be true. This operation captures the notion of "either... or... but not both," emphasizing mutual exclusivity in logical conditions. In its standard two-input form, XOR serves as a core building block in digital circuits and , where it is often implemented using the symbol \oplus to denote the operation between variables or bits. The operator is commutative, meaning pqp \oplus q yields the same result as qpq \oplus p, though detailed properties are explored elsewhere. XOR generalizes to multiple inputs (nn-ary XOR), where the output is true if and only if an odd number of the inputs are true, providing a parity-checking mechanism in applications like error detection. However, the binary case remains the primary focus for defining the operation's intuitive and formal behavior.

Truth Table

The truth table for the exclusive or (XOR) operation with two inputs, typically denoted as pp and qq, exhaustively lists all possible input combinations and their corresponding outputs. The output is true (1) exactly one of the inputs is true, and false (0) otherwise.
ppqqpqp \oplus q
000
011
101
110
This table demonstrates that the XOR output is true precisely when the inputs differ, capturing the operation's emphasis on between the propositions. In contrast to the inclusive or (OR), which yields true whenever at least one input is true (including both true), the XOR truth table highlights its distinct behavior by producing false when both inputs are true, thereby excluding the case of mutual truth. For three inputs, say pp, qq, and rr, the multi-input XOR extends the operation to produce true if an odd number of inputs are true (specifically, one or all three), embodying the concept of odd parity. The full for three inputs confirms this pattern across all eight combinations, where the output is 1 for inputs with exactly one 1 or three 1s, and 0 otherwise.

Logical Expressions

Equivalences

The exclusive or operation, denoted as pqp \oplus q or pp XOR qq, can be expressed in terms of more primitive logical connectives: conjunction (\wedge), disjunction (\vee), and negation (¬\neg). One primary equivalence is the disjunctive normal form:
pq(p¬q)(¬pq).p \oplus q \equiv (p \wedge \neg q) \vee (\neg p \wedge q).
This form captures the cases where exactly one of pp or qq is true, by conjoining each proposition with the negation of the other and then taking their disjunction.
An alternative equivalence relates XOR to the inclusive or (\vee) by excluding the case where both are true:
pq(pq)¬(pq).p \oplus q \equiv (p \vee q) \wedge \neg (p \wedge q).
This emphasizes the union of pp and qq minus their , providing a compact representation useful in certain proof contexts.
In logical proofs and , an elimination rule for XOR involves replacing instances of pqp \oplus q with its disjunctive form (p¬q)(¬pq)(p \wedge \neg q) \vee (\neg p \wedge q) to simplify formulas or convert to a standard normal form without the XOR connective. Conversely, an introduction rule allows inserting XOR by recognizing the conjunction-disjunction pattern (p¬q)(¬pq)(p \wedge \neg q) \vee (\neg p \wedge q) and substituting pqp \oplus q, facilitating modular reasoning or equivalence transformations. These rules preserve and are standard in propositional logic derivations. Both equivalences can be verified through truth table comparison, as detailed in the for XOR. Constructing a truth table for the right-hand side of each equivalence yields identical truth values to the XOR column across all four input combinations of pp and qq, confirming the equivalences hold tautologically.

Negation

The negation of the exclusive or operation, denoted as ¬(p ⊕ q), is logically equivalent to the expression (p ∧ q) ∨ (¬p ∧ ¬q), which holds true when both propositions and are either true or false. This form represents the exclusive nor (XNOR) operator and is also identical to the biconditional p ↔ . The equivalence arises because XOR is true only when p and q differ in truth value, so its negation is true precisely when they share the same truth value. This core identity can be derived by applying De Morgan's laws to the disjunctive normal form of XOR, p ⊕ q ≡ (p ∧ ¬q) ∨ (¬p ∧ q): ¬(pq)¬[(p¬q)(¬pq)]¬(p¬q)¬(¬pq)(¬pq)(p¬q)(pq)(¬p¬q).\begin{align*} ¬(p ⊕ q) &\equiv ¬[(p ∧ ¬q) ∨ (¬p ∧ q)] \\ &\equiv ¬(p ∧ ¬q) ∧ ¬(¬p ∧ q) \\ &\equiv (¬p ∨ q) ∧ (p ∨ ¬q) \\ &\equiv (p ∧ q) ∨ (¬p ∧ ¬q). \end{align*} A symmetry property of XOR negation states that negating one input produces the same result as negating the entire operation: ¬p ⊕ q ≡ p ⊕ ¬q ≡ ¬(p ⊕ q) ≡ p ↔ q. This holds because flipping the truth value of one operand in XOR inverts the overall parity, mirroring the effect of direct negation on the output. De Morgan-like dualities for XOR emerge from the above derivation, where the outer distributes over the disjunction in XOR's expression, transforming OR into AND and negating the inner components—analogous to standard De Morgan rules but tailored to XOR's structure of differing inputs. This duality highlights XOR's role in parity logic, enabling simplifications in and proof systems. For example, negating XOR yields the biconditional, which formalizes "p if and only if q" as true only when p and q are equivalent in truth value; this is evident in applications like equivalence checking, where ¬(p ⊕ q) confirms matching states without the exclusion of XOR.

Algebraic Aspects

Properties

The exclusive or (XOR) operation, denoted as \oplus, exhibits several fundamental properties within Boolean algebra that distinguish it from other binary operators like AND (\wedge) and OR (\vee). These properties arise from its definition as the operator that yields true if and only if its inputs differ, and they underpin its utility in logical expressions and computations. XOR is commutative, meaning the order of operands does not affect the result: pqqpp \oplus q \equiv q \oplus p. This symmetry holds because the truth value depends solely on whether the inputs differ, regardless of . Similarly, XOR is associative, allowing parentheses to be omitted in multi-operand expressions: (pq)rp(qr)(p \oplus q) \oplus r \equiv p \oplus (q \oplus r). Associativity ensures consistent evaluation across chained operations, as the overall parity of true inputs determines the outcome. Unlike AND and OR, which are idempotent (pppp \wedge p \equiv p and pppp \vee p \equiv p), XOR is non-idempotent: ppp \oplus p \equiv \bot, where \bot denotes false. This property reflects XOR's role in toggling or canceling identical inputs. The constant false serves as the for XOR: ppp \oplus \bot \equiv p, preserving the unchanged. Furthermore, each value acts as its own inverse under XOR, reinforcing the self-canceling behavior: ppp \oplus p \equiv \bot. In terms of distributivity, AND distributes over XOR: p(qr)(pq)(pr)p \wedge (q \oplus r) \equiv (p \wedge q) \oplus (p \wedge r), enabling in expressions involving these operators. However, XOR does not distribute over OR. This selective distributivity aligns with XOR's interpretation as modulo 2 in the field of two elements (GF(2)), where AND corresponds to . When extended to binary representations, XOR operates linearly bit by bit, equivalent to vector addition modulo 2. For multi-bit numbers, each bit position computes independently as aibimod2a_i \oplus b_i \mod 2, without carry propagation, facilitating efficient parity checks and error detection.

Relation to Modern Algebra

In modern algebra, the exclusive or (XOR) operation finds a natural interpretation as the addition in the finite field F2=GF(2)\mathbb{F}_2 = \mathrm{GF}(2), whose elements are {0,1}\{0, 1\} with arithmetic modulo 2. Here, addition corresponds to XOR (where 00=00 \oplus 0 = 0, 01=10 \oplus 1 = 1, 10=11 \oplus 0 = 1, 11=01 \oplus 1 = 0), and multiplication corresponds to the logical AND operation (where 00=00 \land 0 = 0, 01=00 \land 1 = 0, 10=01 \land 0 = 0, 11=11 \land 1 = 1). This structure equips F2\mathbb{F}_2 with the properties of a field, including distributivity: (ab)c=(ac)(bc)(a \oplus b) \land c = (a \land c) \oplus (b \land c). Extending this, the set of all Boolean functions on nn variables, under pointwise XOR as addition and pointwise AND as multiplication, forms a Boolean ring, a commutative ring where every element is idempotent (ff=ff \land f = f for any function ff). The collection of all nn-bit binary strings, denoted {0,1}n\{0,1\}^n, equipped with bitwise XOR as the , constitutes an isomorphic to (Z/2Z)n(\mathbb{Z}/2\mathbb{Z})^n. The is the zero vector (all bits , representing false), and the operation is commutative and associative, with every element serving as its own inverse: for any string xx, xx=[0](/page/0)x \oplus x = [0](/page/0). This group structure arises directly from the properties over F2\mathbb{F}_2, where by annihilates any vector and multiplication by 1 leaves it unchanged. More broadly, {0,1}n\{0,1\}^n forms an nn-dimensional over F2\mathbb{F}_2, with XOR as vector addition and the field scalars {0,1}\{0,1\} acting componentwise. A basis for this space consists of the vectors eie_i (with a 1 in the ii-th position and 0s elsewhere), and of a set of vectors {v1,,vk}\{v_1, \dots, v_k\} holds if no nonempty sums (via XOR) to the zero vector; equivalently, the n×kn \times k matrix formed by these vectors as columns has full column rank over F2\mathbb{F}_2. Any nn-bit string can be uniquely expressed as a of a basis, highlighting XOR's role in encoding linear dependencies among . Systems of linear equations involving XOR operations, such as j=1naijxj=bi\sum_{j=1}^n a_{ij} x_j = b_i for i=1,,mi=1,\dots,m where coefficients and bib_i are in {0,1}\{0,1\} and summation is XOR, can be solved using performed modulo 2. This process row-reduces the augmented coefficient matrix over F2\mathbb{F}_2 to , identifying the solution space (affine subspace if consistent) or detecting inconsistency if a row reduces to [001][0 \dots 0 \mid 1]. The is O(min(m,n)2max(m,n))O(\min(m,n)^2 \max(m,n)), making it efficient for sparse systems common in algebraic contexts. An important extension is the representation of Boolean functions via Zhegalkin polynomials, also known as the (ANF), which express any function f:{0,1}n{0,1}f: \{0,1\}^n \to \{0,1\} as a over F2\mathbb{F}_2: f(x1,,xn)=ScSiSxif(x_1,\dots,x_n) = \bigoplus_{S \subseteq } c_S \bigwedge_{i \in S} x_i, where \bigoplus denotes XOR (addition in F2\mathbb{F}_2), \bigwedge denotes AND (multiplication), and coefficients cS{0,1}c_S \in \{0,1\} are determined by Möbius inversion on the subset lattice. This XOR-of-ANDs form is unique, canonical, and facilitates analysis of function properties like nonlinearity and algebraic immunity, as the degree equals the highest S|S| with cS=1c_S = 1.

Notation and Language

Alternative Symbols

The primary symbol for exclusive or is the circled plus ⊕ (Unicode U+2295), introduced by mathematician Edward V. Huntington in his 1904 paper on independent postulates for the algebra of logic to denote . This notation was adopted by in his 1938 master's thesis, A Symbolic Analysis of Relay and Switching Circuits, where it appeared in diagrams representing relay-based exclusive disjunction operations. In , it is rendered using the command \oplus. Other notations include the caret ^, widely used in programming languages for bitwise exclusive or; for example, in C, C++, Java, and Python, a ^ b computes the bitwise XOR of integers a and b. In Polish notation systems, logician Józef Maria Bocheński assigned the symbol J in his 1949 extension of Łukasiewicz's notation to cover all 16 binary connectives, where Jpq denotes the exclusive disjunction of p and q. Some early logical texts used the inequality symbol ≠ to represent exclusive or, emphasizing its function as logical inequality (true when operands differ). Contextual variations appear in specialized domains: the slashed disjunction ∨̸ (Unicode U+22C0, LaTeX \not\vee or \veebar) denotes exclusive disjunction in certain formal logic contexts to distinguish it from inclusive or. In Boolean algebra interpreted as a ring over GF(2), the addition operator + serves as exclusive or, aligning with modular arithmetic where addition modulo 2 yields the symmetric difference. The evolution of these symbols traces from early 20th-century algebraic logic, where Huntington's ⊕ formalized Boolean operations, through Shannon's application to electrical engineering in the 1930s, to mid-century digital circuit design, where IEEE standards defined graphical symbols for logic functions including XOR in diagrams, alongside algebraic notations like ⊕ and ⊻ (Unicode U+22BB, LaTeX \veebar) in mathematical texts, and finally to 1970s programming standards like ASCII, which assigned ^ for efficient bitwise operations in languages such as B and C.

Usage in Natural Language

In natural language, the English word "or" frequently conveys an exclusive disjunction, implying that only one of the alternatives can hold true, even though its semantic core is inclusive. For instance, the common query "Would you like tea or coffee?" typically suggests choosing one beverage, not both, as responding with both would often require clarification like "or both?" This exclusive interpretation arises in everyday scenarios where alternatives are mutually limiting, such as selecting "pie or cake" from a limited menu portion. This usage introduces ambiguity between inclusive and exclusive meanings, which can lead to misunderstandings, particularly in precise domains like . In legal drafting, "or" is often treated as inclusive unless specified otherwise, but phrases like "either...or" explicitly signal exclusivity to avoid disputes over joint fulfillment. For example, a stating "the buyer shall pay by cash or check" might allow both if inclusive, but "either cash or check" enforces selection of one to prevent in obligations. Courts have interpreted "either...or" as denoting exclusive disjunction in English legal contexts, contrasting with more flexible uses in other languages. Cross-linguistically, interpretations vary: French "ou" tends toward exclusivity in simple disjunctions, as in "thé ou café," where both would violate the implied choice, though complex forms like "ou...ou" can reinforce this. In Spanish, "o" is more context-dependent, functioning as inclusive or exclusive based on , similar to English but without a strict default, as seen in phrases like "té o café" that allow both unless specified. These differences highlight how disjunctive particles encode exclusivity through convention rather than universal semantics. Philosophically, the exclusive flavor of "or" in natural language stems from Gricean implicature, where speakers adhere to the maxim of —providing no more than needed—leading hearers to infer exclusivity from an inclusive statement. For example, saying "John bought apples or oranges" implicates "but not both" because mentioning both would be more informative if true, unless cancels the implicature. This pragmatic mechanism explains why inclusive "or" often sounds exclusive without altering literal meaning. Common phrases and literary examples further illustrate this: the idiom "you can't have your cake and eat it too" embodies exclusive disjunction by asserting the impossibility of simultaneous possession and consumption, underscoring mutually exclusive options. In literature, such as Lewis Carroll's Through the Looking-Glass, the White Queen's offer of "jam tomorrow and jam yesterday—but never jam today" plays on exclusive alternatives to highlight logical paradoxes in choice. These expressions reinforce how everyday prioritizes exclusivity for clarity in decision-making.

Applications

Computer Science

In computer science, the exclusive or (XOR) operation is fundamental as a bitwise operator that performs a logical exclusive OR on corresponding bits of two binary numbers, producing a 1 in each bit position where the inputs differ and 0 where they are the same. This bitwise XOR is applied independently to each bit pair, making it efficient for integer manipulation in programming languages. For instance, in binary, 5 (101) XOR 3 (011) yields 6 (110), as the first and third bits differ while the second matches. Languages like C, C++, and Python use the caret symbol (^) to denote this operator, allowing direct application to integers for tasks such as bit flipping or masking. One notable application of bitwise XOR is the , which exchanges the values of two variables without requiring temporary storage, leveraging the property that XORing a value with itself yields and XORing with preserves the value. The steps are: a = a ^ b; b = a ^ b; a = a ^ b;, where the first step stores the XOR of both in a, the second recovers the original a in b, and the third extracts the original b in a. This technique, while historically useful in memory-constrained environments, is now often optimized or avoided by modern compilers in favor of explicit temporary variables for clarity. The XOR symbol ⊕ is encoded in Unicode as U+2295 (Circled Plus) within the Mathematical Operators block, enabling its use in documentation and code comments across systems supporting . In programming, the operator ^ is standard in many languages, including and , where it applies to integers or BigInts bit by bit. XOR plays a key role in data structures for hashing and error detection. In hashing, it is commonly used to combine multiple hash values, such as folding bits or merging sub-hashes, due to its commutative and associative properties that help distribute values evenly without order dependency. For checksums, XOR computes parity bits in error-detecting codes; an even parity bit is the XOR of all data bits set to make the total XOR zero, detecting single-bit errors in transmission by verifying if the received parity matches. At the hardware level, XOR is implemented using XOR gates in digital circuits, which output 1 only for an odd number of 1 inputs and are essential in arithmetic logic units (ALUs) for , , and . These gates typically require a low gate count, such as four NAND gates for a two-input XOR, making them cost-effective in VLSI design.

Other Fields

In , the exclusive or (XOR) operation serves as a foundational primitive for achieving . The cipher, introduced by in and analyzed by in 1949, encrypts by XORing it bit-by-bit with a random key of equal , ensuring perfect because the reveals no information about the without the key. Stream ciphers like , designed by in 1987, generate a pseudorandom keystream via a key-scheduling and XOR it with the to produce , enabling efficient symmetric encryption despite vulnerabilities identified in later . XOR plays a central role in error detection and correction mechanisms across engineering domains. In redundant array of independent disks (RAID) systems, particularly RAID levels 3, 4, and 5, parity information is computed using XOR across data blocks on multiple drives, allowing reconstruction of lost data by XORing the surviving blocks with the parity block to identify and recover from single-drive failures. Hamming codes, developed by in 1950, treat error correction as linear algebra over the GF(2), where addition is XOR; parity-check matrices enable detection and correction of single-bit errors in by solving for the error position through syndrome computation. In and , XOR facilitates efficient computations in resource-constrained environments. Binary neural networks (BNNs), which quantize weights and activations to 1-bit values (±1), approximate multiplications using binary operations such as XNOR and popcount for in standard implementations, reducing memory and computational demands by up to 32 times compared to full-precision models while maintaining reasonable accuracy on tasks like image classification. Optimized variants like XOR-Net use XOR and bitcount instead to further reduce operations. Post-2020 advancements in leverage XOR-like differences to capture nonlinear interactions; for instance, benchmarks using synthetic XOR datasets evaluate models' ability to identify synergistic feature pairs that only contribute when differing, aiding interpretable AI in high-dimensional data like . These techniques have driven efficient AI hardware designs, such as XOR-Net pipelines on edge devices, achieving 17% faster and 19% better energy efficiency than prior BNN accelerators like XNOR-Net. Quantum computing employs XOR principles in gate-based operations for entanglement. The controlled-NOT (CNOT) gate, a universal two-qubit gate, acts as a controlled-XOR: it leaves the control qubit unchanged while flipping the target qubit (applying a Pauli-X operation) if the control is in the |1⟩ state, enabling the creation of entangled states like Bell pairs essential for quantum algorithms such as and error correction. In broader engineering applications, XOR detects differences in tasks. XOR-based phase detectors in phase-locked loops (PLLs) compare clock and data signals by producing pulses proportional to their phase difference up to 180 degrees, facilitating in digital communication systems like serial links. In genetics, XOR parity models epistatic interactions among single nucleotide polymorphisms (SNPs); for example, higher-order epistasis analysis uses XOR to detect allele combinations where phenotypic effects depend on the parity of differing SNPs, as in quantitative trait loci studies revealing nonlinear gene interactions in susceptibility.

History

Origins

In the 19th century, these ideas advanced through and related developments in symbolic logic. , in his 1847 book Formal Logic; or, the Calculus of Inference, Necessary and Probable, explored alternative and contrary propositions, introducing extensions to traditional syllogistic logic that accounted for "contraries"—propositions that cannot both be true, akin to the of conjunction in exclusive disjunction. De Morgan's treatment of alternatives as incompatible options provided a clearer framework for what would later be recognized as exclusive aspects of disjunction, bridging Aristotelian categories with emerging algebraic methods. George Boole further implied the exclusive or through set-like operations in his seminal 1854 work An Investigation of the Laws of Thought, on Which are Founded the Mathematical Theories of Logic and Probabilities. Boole defined the symmetric difference between classes as x(1y)+y(1x)x(1 - y) + y(1 - x), which corresponds precisely to the exclusive or: true when one but not both elements hold. This algebraic representation treated logical differences as operations excluding overlap, influencing subsequent probability and logic theories. The ancient Stoics developed early propositional logic, including forms of disjunction, though not formalized as exclusive disjunction separate from inclusive cases. By the early , formalization progressed with Jan Łukasiewicz's contributions to propositional logic. In the , Łukasiewicz developed (prefix notation) as a parenthesis-free system for expressing logical connectives, including exclusive disjunction, in works such as his 1920 paper "O logice trójwartościowej" (On ) and related publications. This notation explicitly incorporated exclusive disjunction (often denoted as "A E B" or similar in his system) as a binary operator, enabling precise representation of statements where exactly one disjunct is true, and facilitating the analysis of many-valued logics beyond binary truth values. Pre-digital recognition of exclusive or also appeared in through the concept of , visually represented in Venn diagrams. Introduced by in his 1881 paper "On the Diagrammatic and Mechanical Representation of Propositions and Reasonings," these diagrams illustrate the symmetric difference of events A and B as the regions in A or B but not their , corresponding to the probability P(A Δ B) = P(A) + P(B) - 2P(A ∩ B). This geometric depiction highlighted the exclusive nature of the operation in set and probability contexts long before computational applications.

Development

Claude Shannon's 1938 master's thesis, "A Symbolic Analysis of Relay and Switching Circuits," established the foundation for applying to electrical switching systems, including the representation of the exclusive-or operation in diagrams using the symbol ⊕ to denote or modulo-2 addition. This work demonstrated how XOR could model the behavior of contacts that close only when exactly one input is active, enabling systematic design of complex circuits. Following , XOR became integral to the emerging field of digital logic design during the 1940s and 1950s, as exemplified by John von Neumann's contributions to the project, which incorporated operations including XOR for arithmetic and control functions in stored-program computers. Engineers at institutions like the Moore School of Electrical Engineering built on Shannon's principles to implement XOR in vacuum-tube-based logic gates, facilitating the transition from electromechanical relays to fully electronic computing systems. In the and , XOR achieved standardization in hardware through transistor-transistor logic (TTL) families, with introducing the 7400 series of integrated circuits in 1964, including dedicated XOR gates like the 7486 quad exclusive-or chip by the late . Concurrently, programming languages adopted XOR operators; 77 (standardized in 1978) included the .NEQV. operator for logical exclusive OR, while bitwise XOR was provided by extensions like IEOR in later standards; the C language, developed by at in 1972, used the ^ symbol for bitwise XOR, promoting its use in and embedded applications through the 1980s. The 1990s and 2000s saw XOR's prominence in , particularly with the (AES), published by NIST as FIPS 197 in 2001, where XOR operations form the core of the AddRoundKey step, combining state bytes with round keys across 10–14 rounds depending on key length. This standardization drove widespread adoption of XOR in secure communications protocols, influencing designs in SSL/TLS and during the 2010s. Post-2020 advancements have highlighted XOR's role in neuromorphic computing, where memristor-based devices using 2D materials enable low-power with energy efficiencies below 1 pJ per operation. In , surface codes—pioneered for fault-tolerant —rely on XOR-like parity checks in syndrome decoding; IBM's 2025 roadmap integrates surface code variants with qLDPC enhancements on processors like Heron, while Google's 2024 Willow chip demonstrated exponential error suppression using surface code logical qubits with 105-qubit patches.

References

Add your contribution
Related Hubs
Contribute something
User Avatar
No comments yet.