In Depth
See Also

Exclusive disjunction

Exclusive disjunction, also known as exclusive or and symbolized by XOR or EOR, is a logical operation on two operands that results in a logical value of true if and only if one of the operands, but not both, has a value of true.

Discussions

  Discussion Features

   Ask a question about 'Exclusive disjunction'

   Start a new discussion about 'Exclusive disjunction'

   Answer questions about 'Exclusive disjunction'

   'Exclusive disjunction' discussion forum


Encyclopedia

Exclusive disjunction, also known as exclusive or and symbolized by XOR or EOR, is a logical operation on two operands that results in a logical value of true if and only if one of the operands, but not both, has a value of true.


Definition


In many natural languages, English English language

English is a widely distributed language that originated in England [i] but is now the primary language ... 

 included, the interpretation of the word "or" requires a certain amount of care. The exclusive disjunction of a pair of propositions, , means that p is true or q is true, but not both. For example, the normal intention of a statement like "You can follow the rules or be disqualified" is to stipulate that exactly one of the conditions can be true. In logic, however, the default meaning of the word "or" is the inclusive disjunction Logical disjunction

In logic [i] and mathematics [i], logical disjunction is a logical operator [i] that results in true ju ... 

, which signifies that at least one of the alternatives is true. Other languages, such as Latin Latin

Latin is an ancient Indo-European language [i] originally spoken in Latium [i], ... 

, may have different words for these different types of "or".

Exclusive disjunction is an operation on two logical values, typically the values of two propositions, that produces a value of true just in case exactly one of its operands is true.

The truth table of p XOR q is as follows:

Exclusive Disjunction
p q p XOR q
F F F
F T T
T F T
T T F


The following equivalents can then be deduced:




Generalized or n-ary XOR is true when the number of 1-bits is odd.

Alternative symbols

The symbol used for exclusive disjunction varies from one field of application to the next, and even depends on the properties being emphaisized in a given context of discussion. In addition to the abbreviation "XOR", any of the following symbols may also be seen:
  • A plus sign . This makes sense mathematically because exclusive disjunction corresponds to addition Addition

    Addition is the mathematical operation [i] of increasing one amount by another. ... 

     modulo 2, which has the following addition table, clearly isomorphic to the one above:


Addition Modulo 2
p q p + q
0 0 0
0 1 1
1 0 1
1 1 0


  • The use of the plus sign has the added advantage that all of the ordinary algebraic properties of mathematical rings and fields can be used without further ado.
  • A plus sign that is modified in some way, such as being encircled . This usage faces the objection that this same symbol is already used in mathematics for the direct sum of algebraic structures.
  • An inclusive disjunction symbol that is modified in some way, such as being underlined .
  • In several programming language Programming language

    A programming language is an artificial language [i] that can be used to control [i] ... 

    s, such as C C (programming language)

    The C programming language is a general-purpose, procedural [i], imperative [i] ... 

    , C++ C++

    C++ is a general-purpose, high-level [i] programming language [i] with low-level [i] facilities. ... 

     and Java Java (programming language)

    Java is an object-oriented [i] programming language [i] developed by James Gosling [i] ... 

    , a caret is used to denote the bitwise XOR operator, while boolean XOR is denoted ^^. This is not used outside of programming contexts because it is too easily confused with other uses of the caret.
  • The symbol
    .

Equivalent expressions


The exclusive disjunction can be expressed in terms of the conjunction , the disjunction , 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. The proof of this identity is given below:




It is sometimes useful to write p XOR q in the following way:




This equivalence can be established by applying De Morgan's laws twice to the fourth line of the above proof.

Associativity and commutativity


In view of the isomorphism between addition modulo 2 and exclusive disjunction, it is clear that XOR is both an associative Associativity

In mathematics [i], associativity is a property that a binary operation [i] can have. ... 

 and a commutative operation. Thus parentheses may be omitted in successive operations and the order of terms makes no difference to the result. For example, we have the following equations:



Properties

This section uses the following symbols:




The following equations follow from logical axioms:



Bitwise operation

Exclusive disjunction is often used for bitwise operations. Examples:

  • 1 xor 1 = 0
  • 1 xor 0 = 1
  • 1110 xor 1001 = 0111


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 .

Computer science


In computer science, exclusive disjunction has several uses:

  • It tells whether two bits are unequal.
  • It is an optional bit-flipper .
  • It tells whether there are an odd number of 1 bits .


On some computer architectures, it is more efficient to store a zero in a register by xor-ing the register with itself instead of loading and storing the value zero. In simple threshold activated neural network Neural network

A neural network is a system [i] of interconnecting neuron [i]s in a network [i] working together to pro... 

s, modelling the 'xor' function requires a second layer because 'xor' is not a linearly-separable function.

Exclusive-or is sometimes used as a simple mixing function in cryptography Cryptography

Cryptography is a discipline of mathematics [i] concerned with information security [i] and related iss ... 

, for example, with one-time pad One-time pad

In cryptography [i], the one-time pad is an encryption [i] algorithm where the plaintext [i] is combine ... 

 or Feistel network Feistel cipher

In cryptography [i], a Feistel cipher is a block cipher [i] with a particular structure, named after IBM [i] ... 

 systems.

XOR is used in RAID RAID

[i] scheme using multiple [[hard drive]... 

 3–6 for creating parity information. For example, RAID can "back up" bytes 10011100 and 01101100 from two hard drives by XORing and writing to an another drive. Under this method, if any one of the four hard drives are lost, the lost byte can be re-created by XORing bytes from the remaining drives. If the drive containing 01101100 is lost, 10011100 and 11110000 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 "one" if there is an overflow.

XOR can be used to swap two numeric variables in computers; however this is regarded as more of a curiosity and not encouraged in practice.

See also


Logical operators

  • Exclusive disjunction
  • Logical conjunction Logical conjunction

    In logic [i] and mathematics [i], logical conjunction is a two-place logical operation [i] that results... 

  • Logical disjunction Logical disjunction

    In logic [i] and mathematics [i], logical disjunction is a logical operator [i] that results in true ju ... 

  • Logical equality Logical equality

    Logical equality is a logical operator [i] that corresponds to equality [i] in boolean algebra [i] ... 

  • Logical implication
  • Logical NAND Sheffer stroke

    The Sheffer stroke, written "|" or "↑", denotes a logical operation [i] that is equivalent to the negation [i] ... 

  • Logical NOR Logical NOR

    The logical NOR or joint denial is a boolean logic [i] operator which produces a result that is th ... 

  • Negation

Related topics

  • Affirming a disjunct
  • Ampheck
  • Boolean algebra Boolean algebra

    In abstract algebra [i], a Boolean algebra is an algebraic structure [i] that captures essential proper ... 

  • Boolean algebra topics
  • Boolean domain
  • Boolean function
  • Boolean logic Boolean logic

    Boolean logic is a complete system for logic [i]al operation [i]s. ... 

  • Boolean-valued function
  • Controlled NOT
  • Disjunctive syllogism
  • First-order logic
  • Logical graph
  • Logical value
  • Minimal negation operator Minimal negation operator

    In logic [i] and mathematics [i], the minimal negation operator is a multigrade operator [i] where eac... 

  • Multigrade operator
  • Operation
  • Operator
  • Parametric operator
  • Parity bit
  • Propositional logic
  • Symmetric difference Symmetric difference

    In mathematics [i], the symmetric difference of two set [i]s is the set of elements which are in one of ... 

  • XOR linked list
  • XOR swap algorithm
  • Zeroth order logic



Categories: