Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Exclusive or
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Computer science== [[File:XOR ANSI Labelled.svg|thumb|right|114px|Traditional symbolic representation of an XOR [[logic gate]]]] ===Bitwise operation=== {{Main article|Bitwise operation}} [[File:Z2^4; Cayley table; binary.svg|thumb|[[Nimber]] addition is the ''exclusive or'' of [[nonnegative integer]]s in [[w:binary numeral system|binary]] representation. This is also the vector addition in <math>(\Z/2\Z)^4</math>.]] 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 * {{n-ary|1110|2}} XOR {{n-ary|1001|2}} = {{n-ary|0111|2}} (this is equivalent to addition without [[carry (arithmetic)|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]] <math>(\Z/2\Z)^n</math>. 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 [[Parity (mathematics)|odd]] number of 1 bits (<math>A \oplus B \oplus C \oplus D \oplus E</math> 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 (electronics)|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 cipher|Feistel network]] systems.{{citation needed|date=June 2015}} 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]]s, modeling the XOR function requires a second layer because XOR is not a [[Linear separability|linearly separable]] function. Similarly, XOR can be used in generating [[entropy pool]]s for [[hardware random number generator]]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.<ref>{{cite web|last=Davies|first=Robert B|title=Exclusive OR (XOR) and hardware random number generators|url=http://www.robertnz.net/pdf/xor2.pdf|access-date=28 August 2013|date=28 February 2002}}</ref> XOR is used in [[RAID]] 3β6 for creating parity information. For example, RAID can "back up" bytes {{n-ary|10011100|2}} and {{n-ary|01101100|2}} from two (or more) hard drives by XORing the just mentioned bytes, resulting in ({{n-ary|11110000|2}}) 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 {{n-ary|01101100|2}} is lost, {{n-ary|10011100|2}} and {{n-ary|11110000|2}} can be XORed to recover the lost byte.<ref>{{cite web|last=Nobel|first=Rickard|title=How RAID 5 actually works|access-date=23 March 2017|date=26 July 2011|url=http://rickardnobel.se/how-raid5-works}}</ref> 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 list]]s 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 volume|bounding boxes]] and [[cursor (computers)|cursors]] on systems without [[alpha compositing|alpha channels]] or overlay planes.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)