Bitwise operation addition is the
exclusive or of
nonnegative integers in
binary representation. This is also the vector addition in (\Z/2\Z)^4. 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 (\Z/2\Z)^n. 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 (A \oplus B \oplus C \oplus D \oplus E 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. 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. XOR is used in
RAID 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, 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==