Nepedia
Back to Discover
Advanced Reader
💻

XOR gate

technology Maturity 11-13 Next article →

An XOR gate is a fundamental component of digital logic used in electronic circuits.

XOR ANSI
XOR ANSI

The name stands for "exclusive OR," though it is also known as EOR or EXOR. This gate is essential because it performs a specific logical operation based on its inputs. It produces a true output, also called a HIGH signal or a 1, only when the number of true inputs is odd.

XOR IEC
XOR IEC

For a standard gate with two inputs, this means the output is true if one, and only one, input is true. If both inputs are false, or if both inputs are true, the output remains false. This makes the XOR gate an inequality function, as it only yields a true result when the inputs are not alike.

Beyond simple logic, the XOR gate can act as a programmable inverter. In this role, one input acts as a control switch for the other. If the control input is set a certain way, the gate will invert the signal, acting like a NOT gate. If the control input is set differently, the gate simply passes the signal through without any change. This flexibility allows engineers to use XOR gates to flip or buffer signals as needed. Mathematically, the operation can also be viewed as addition modulo 2, which is a key concept in digital arithmetic.

Engineers use several different methods to implement XOR gates in physical hardware.

CmosXORGate
CmosXORGate

One common method is using CMOS, or metal–oxide–semiconductor technology. In a CMOS implementation, nMOS and pMOS transistors are arranged to connect the output to either the supply voltage (Vdd) for a HIGH signal or to the ground (Vss) for a LOW signal. If the circuit does not already have inverted inputs available, it may require two additional inverters, bringing the total to twelve transistors. This specific AOI (AND-OR-invert) logic style was used, for example, in the Intel 386 CPU.

Another implementation method uses transmission gates with pass transistor logic.

XOR gate implemented with pass gates
XOR gate implemented with pass gates

This design is often more efficient, using only eight transistors, which is four fewer than the standard CMOS design. In this setup, the gate passes the inverted value of input A when input B is high. When B is low, the gate passes the original value of A. While this saves space, there is a trade-off. Transmission gates are not ideal switches and have some resistance. If many gates are connected in a row, known as cascading, the signal strength might degrade.

Advanced designs can optimize this even further to use only six transistors.

XOR from NAND
XOR from NAND

This optimized version uses a specific arrangement of transistors to perform conditional inversion with fewer components. If a specific XOR gate is not available in a circuit, it can be built using other types of gates. NAND and NOR gates are known as "universal gates" because they can be used to construct any other logic function. For instance, an XOR gate can be built using only four NAND gates or a specific arrangement of NOR gates. Using a mix of AND, OR, and NOT gates is possible, but it can require up to five gates to achieve the same result.

In the world of computing, XOR gates are vital for performing binary addition.

Half Adder
Half Adder

They are a primary part of a half adder, which combines an XOR gate with an AND gate. In binary addition, the XOR gate produces the sum bit, while the AND gate produces the carry bit. By chaining these circuits together into full adders, computers can add much larger numbers. XOR gates are also used in subtractors and comparators, making them essential for almost all mathematical processing in a CPU.

These gates also play a role in more complex digital systems like pseudo-random number generators.

LFSR-G16
LFSR-G16

Specifically, they are used in linear-feedback shift registers (LFSR) to create sequences of numbers that appear random. Additionally, XOR gates are used in communication devices as correlators. They can compare a long string of data against a target pattern to see how well they match. In a CDMA receiver, for example, they help extract specific signals from a collection of many different signals. From simple math to complex communication, the XOR gate is a building block of the modern digital age.

700 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

🖼️ Images & Media (16)
File:XOR ANSI.svg
XOR ANSI.svg
File:XOR IEC.svg
XOR IEC.svg
File:XOR DIN.svg
XOR DIN.svg
File:XOR gate implemented with pass gates.svg
XOR gate implemented with pass gates.svg
File:CmosXORGate.png
CmosXORGate.png
File:ANDNOR XOR Gate implementation.png
ANDNOR XOR Gate implementation.png
File:254px 3gate XOR.svg
254px 3gate XOR.svg
File:XOR ANSI Labelled.svg
XOR ANSI Labelled.svg
File:XOR from NAND.svg
XOR from NAND.svg
File:XOR from NOR 2.svg
XOR from NOR 2.svg
File:XOR from NAND 2.svg
XOR from NAND 2.svg
File:XOR from NOR.svg
XOR from NOR.svg

+ 4 more

More to explore

🔬 Go deeper

More advanced topics to explore

🪜 Step back

Simpler topics to build understanding

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.