The Wayback Machine - https://web.archive.org/web/20240910201906/https://www.geeksforgeeks.org/xor-gate/
Open In App

XOR Gate

Last Updated : 13 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The XOR or Exclusive OR Gate is a special type of logic gate used in digital electronics to perform the exclusive OR operation. The XOR gate takes two inputs and produces an output depending on the combination of the two inputs applied.

In, this article will explain the complete theory of the XOR gate along with its truth table, Boolean expression, logic symbol, circuit diagram, and more.

Table of Content

  • What is XOR Gate?
  • Construction of XOR Gate Using Transistor
  • XOR GATE Implementation using NAND GATE
  • XOR GATE Implementation using NOR GATE
  • Three Input XOR GATE
  • Applications of XOR Gate
  • Advantages and Disadvantages
  • Solved Example of XOR Gate
  • Conclusion
  • Frequently Asked Questions (FAQ’s)

What is XOR Gate?

In digital electronics, there is a logic circuit called XOR Gate that takes two inputs and produces an output which is the result of the exclusive OR operation performed on the combination of inputs. This logic gate produces a high or logic 1 output when both of the inputs are dissimilar, otherwise, it produces a logic 0 output.

Operations of XOR Gate

We can explain the operation of the XOR gate as follows:

Returns 1, if the number of logical high input is odd.

Returns 0, if number of logical high input is even.

Say we have two inputs, A and B and the output is called X, then the expression is:

The Boolean expression of XOR Gate is as follows:

X = A’B + AB’

Symbol of XOR Gate

The logic symbol of XOR gate is shown in the following figure. In this figure, the variables A and B represent the input lines and A’B + AB’ is the output of the XOR gate.

XOR-Gate with truth table

XOR Gate Logic Symbol and Truth Table

Truth Table of XOR Gate

The truth table of an XOR gate is given below. This table shows the relationship between inputs and output of the XOR gate. This also provides information about the operation of XOR gate for different input combinations.

It is important to note that we do not have a single XOR gate with three or more input lines. Only two input XOR gate exists. But in case if we need an XOR gate which has more than two input lines, we simply combine multiple two-input XOR gates to obtain the desired XOR gate.

Construction of XOR Gate Using Transistor

We can implement exclusive OR gate using transistor. Here is the circuit showing the connection of different circuit elements that are combined to implement the XOR operation.

XOR Gate using NPN Transistor

XOR Gate using NPN Transistor

Working of the Circuit

We will understand this circuit with the help of different scenarios of input in case of 2 input XOR gate:

CASE I: When both the inputs are zero. (A=0, B=0)

When both the inputs A and B are zero then transistors Q1,Q2,Q4 and Q5 are open circuit so the LED will not glow because both Q4 and Q5 are open so the negative pin of LED is not connected to the ground.

CASE II: When one input if logical high and other is logical low (A=1, B=0)

In this case we can easily see that Q4 is working as close circuit now. So the negative pin of the LED is connected to Q3 via Q4 and ultimately which is connected to ground so in this case LED will glow.

CASE III – When one input if logical high and other is logical low (A=0, B=1)

In this case we can easily see that Q5 is working as close circuit now. So the negative pin of the LED is connected to Q3 via Q5 and ultimately which is connected to ground so in this case LED will glow.

CASE IV – When both the inputs are logical high. (A=1, B=1)

In this case when both A and B are logical high then transistor Q1 and Q2 are also activated then the current will directly go from +5V junction to ground through Q1 and Q2 transistors, and will not got in the path where Q3 is connected as a result transistor Q3 will now act as open circuit and ultimately negative pin of LED is disconnected from ground so the LED will not glow.

XOR GATE Implementation using NAND GATE

Expression of XOR gate: A‘.B + A.B‘

To Convert the expression into NAND form perform the following:

Apply double complement: [(A’.B + A.B’)’]’

Operate internal complement: [ (A’.B)’ . (A.B’)’ ]’

Now, expression is obtained in NAND form.

Pass Input A through the first NAND Gate to get A’, now pass this A’ and B through the second NAND Gate to get (A’.B)’. Similarly, pass Input B through the third NAND Gate to get B’, now pass this B’ and A through the fourth NAND Gate to get (A.B’)’. Pass both the output (A’.B)’ and (A.B’)’ through the fifth NAND Gate to get our desired expression of XOR Gate ((A’.B)’.(A.B’)’)’ = A’B + AB’ (By De-Morgans Law).

Logic diagram

The Logical Diagram of the Following Expression is shown below

XOR_USING_NAND

XOR Gate from NAND Gate

XOR GATE Implementation using NOR GATE

To implement XOR gate from NOR gate we follow below steps

  • First, we connect both the inputs in NOR gate resulting in (A + B)’.
  • Then, after we have another two NOR gates with the inputs A, (A + B)’ and B, (A + B)’ respectively with outputs [A + (A + B)’]’ and [B + (A + B)’]’.
  • Again, the connect outputs of the above NOR gates to next NOR gate resulting in the output [A’B + AB’]’.
  • Now, the result is generated in complement form so, we connect the result as the input for last NOR gate which gives the output [AB’ + A’B].
  • The resultant of the last NOR gate gives us XOR gate.
  • So, the number of NOR gates required to implement XOR gate is 5.

below is the logic diagram for implementation of XOR gate from NOR gate:

XOR_USING_NOR

Three Input XOR GATE

The logic circuit diagram of the XOR gate is shown in the following figure. It has three input line denoted by the letter A,B,C and one output line denoted by the letter X, where X=A⊕B⊕C

The Boolean expression of N input XOR Gate is as follows:

3-Input-XOR-Gate-1024

3 Input XOR Gate

Say we have N inputs, A0,A1,…,AN and the output is called X, the expression is:

X=A0⊕A1⊕….⊕AN

Truth Table of Three input XOR Gate

The truth table of three input XOR gate is given below. This table shows the relationship between three inputs and one output of the XOR gate. This also provides information about the operation of XOR gate for different input combinations.

Say we have three inputs A,B and C and the output is called X, then the expression is:

X = A⊕B⊕C

Applications of XOR Gate

Here are some of the applications of the XOR Gate:

  1. Data Encryption: XOR gates are used in data encryption algorithms. As it is used to combine data with secret key to scramble it making it very difficult for unauthorized people to crack.
  2. Comparator Circuits: It is used in comparator circuit to check if the two binary values are equal or not. As for same type of both the input it gives output 0 and for different inputs it gives output 1.
  3. Binary addition and subtraction: It helps in determining sum of each bit and also combine with other logic gates to handle borrow operations.
  4. Toggle Flip flops: In T flip flops it is used to the circuit that toggles with each clock pulse passed.

Some other uses of XOR gates are in Address decoding, Security and access control, Random number generation, clock synchronization, frequency divider circuits etc.

Advantages of XOR Gate

  • It helps to detect if there are odd number of ‘1’ in the sequence of inputs.
  • XOR gates perform the exclusive OR operation, which is a fundamental operation in digital logic.

Disadvantages of XOR Gate

  • XOR gate are complex gate circuit and upon connecting it to the circuit of our use, it causes increased power consumption and circuit complexity.
  • It leads to increase in the propagation delay of the circuit.
  • Upon increasing the number of inputs the circuit becomes more and more complex making it hard to maintain and detect errors.

Solved Example of XOR Gate

Find a single number from a series of numbers given that every element appears twice except for that one single element.

Solution: We know that XOR of two same bits gives ‘0’ so here we can observe that if we XOR the elements then every elements which are occurring twice will become ‘0’ and only remaining element would be our answer.

Like out of [7,2,2,3,3,4,4,5,5,6,6]

If we XOR each of the above elements then elements occurring even number of times will give ‘0’ and elements occurring odd number of times will give the output. Ultimately we will get 7 as output as only this element is occurring once only and rest other elements are occurring even number of times.

Conclusion

In this article we have learnt about the XOR gate. XOR Gate takes Boolean values as input and returns ‘1’, if the number of logical high input is odd and returns 0, if number of logical high input is even.

This article explains the truth table, symbolic representation, solved example, and applications which helps in better understanding of the article.

Frequently Asked Questions on XOR Gate – FAQs

Is XOR gate universal logic gate?

No XOR gate is not universal logic gate, however it can be implemented by means of universal logic gates.

Why XOR and XNOR are special gates?

XOR and XNOR gates are special because they perform exclusive operations essential for error detection, correction, and binary arithmetic, making them foundational in digital logic and computing.

What is XOR for 2 inputs?

For 2 inputs, an XOR (Exclusive OR) gate outputs 1 if and only if one of the inputs is 1 and the other is 0. If both inputs are the same, the output is 0.

What is the symbol of XOR?

The symbol for Exclusive OR(XOR) is ⊕. 

Can XOR have 4 inputs?

Yes, an XOR gate can have more than two inputs. In the case of a 4-input XOR Gate, the output is 1 if an odd number of the inputs are 1. If the number of 1’s in the inputs is even, the output will be 0.

Can XOR gates be used for addition and subtraction?

Yes, XOR gates can be used to perform binary addition and subtraction when combined with other logic gates and carry circuits. They are essential components in binary arithmetic operations.

How do XOR gates behave in terms of binary logic and truth tables?

XOR gates exhibit behavior similar to binary addition modulo 2 (bitwise exclusive OR) and are used to compare and manipulate binary data.



Similar Reads

Implementation of XOR Gate from AND, OR and NOT Gate
In this article, we will discuss the implementation of XOR gate using AND, OR and NOT Gate. We will discuss about the AND, OR, XOR and NOT gates, and with it, we will discuss about their operations, logic diagrams and truth table. After understanding the gates and their operation we will use those gates to design a combinational circuit to replicat
5 min read
Implementation of XOR Gate from NOR Gate
Implementation of the XOR gate from the NOR gate is possible because the NOR gate is a Universal gate i.e., it can implement all other gates. The NOR gate gives the output 1 if all the inputs are 0. XOR gate is a logic gate that gives output 1 when several 1s are odd. In this article, we will explore the XOR gate, and NOR gate and implement the XOR
4 min read
Implementation of XOR Gate from NAND Gate
Logic Gates are the building blocks of digital circuits, taking binary values as input and returning a binary value as output after performing a logical operation. There are several kinds of gates available in Digital Electronics like basic gates, and universal gates. Implementation of the XOR gate from the NAND gate is possible because the NAND ga
5 min read
Difference Between Call Gate, Interrupt Gate, Trap Gate
Gate is used to transfer performance control across all segments. The level of rights assessment is done differently depending on the type of site and the instructions used. Other than that these three gates are almost identical except that Call Gate has parameters for calculating parameters, and that these three gates have different types of field
5 min read
What is the Difference Between XOR and XNOR Gate?
In electronics, Logic Gates are termed as “building blocks of digital circuits”. These gates are used to perform logical operations on single or multiple binary values. In the term “Logic Gate”, a Gate represents a circuit that controls the incoming electric signals. Hence, Logic Gates are those digital circuits through which electric signals can p
4 min read
Implementation of NOR Gate from NAND Gate
Implementation of the NOR gate from the NAND gate is possible because NAND is a Universal gate i.e., it can implement all other gates. The NAND gate gives output low when all the inputs are high whereas the NOR gate gives output high when all inputs are low. In this article, we will implement the NOR gate using the NAND gate. Table of Content NOR G
5 min read
Implementation of XNOR Gate from AOI Gate
Digital electronics revolve around storing data in bits of 1s and 0s. Not only is digital electronics an efficient way of storing data but it also makes it easier to encrypt and secure our data. It is awesome how we can use different logic gates to implement some functions and represent these equations. In this article, we will see how we can repre
6 min read
Implementation of AND Gate from NOR Gate
Digital electronics revolves around storing data in bits of 1s and 0s. Not only is digital electronics an efficient way of storing data but it also makes it easier to encrypt and secure our data. It is awesome how we can use different logic gates to implement some functions and represent these equations. In this article, we will see how we can repr
4 min read
Implementation of AND Gate from NAND Gate
It is worth mentioning that Boolean algebra is a fundamental part of the digital electronics field that uses binary variables and logical operations. Think of it as the mind that makes the computers work effectively. Then, imagine that logic gates (AND, OR, and NOT) could be the necessary helpers in the digital world. These gates are the components
5 min read
Implementation of OR Gate from NOR Gate
The Logic gates are the Fundamental Building Blocks of the Digital Circuits. The Logic Gate takes one or more Binary inputs and performs logical Operations to Produce a single binary Output. Understanding through the Different Combinations of gates is important for the Designer to produce the desired functionality in digital circuits. By Understand
5 min read
Implementation of NOT Gate using NOR Gate
Understanding the concept of logic gates is Fundamental to understanding digital logic circuits. Logic gates are the building blocks of digital circuits responsible for performing the logical operations on binary inputs(0s and 1s) to produce a binary Output. There are many gates such as AND, OR, NOT, NAND, and other logical gates but in this Articl
5 min read
Implementation of NOT Gate using NAND Gate
A universal gate is a logic gate that can be used to implement other types of logic gates. In other words, using a universal gate, you can do all the simple operations like AND, OR, NOT, NAND, and NOR. The two most general purpose NAND gates and NOR gates. These gates are considered universal because they can be used to create all other logic gates
5 min read
Implementation of OR Gate from NAND Gate
Logic gates are an essential component of digital electronics and are used to handle binary data. Because of its universal nature, the NAND gate is particularly significant among these gates. This article explores the use of NAND gates to implement an OR gate, demonstrating the adaptability and usefulness of these fundamental building blocks. In th
4 min read
Difference Between AND Gate and OR Gate
AND gate and OR gate are basic logic gates. AND gate outputs 1 when all inputs are 1 else output 0. OR gate outputs 1 when at least one input is 1 else output 0. The main difference between AND gate and OR gate is that AND gate represents logical conjunction whereas OR gate represents logical disjunction. In this article we will explore difference
4 min read
Difference Between NAND GATE and NOR GATE
NAND and NOR gates are universal logic gates, which means any Boolean expression can be implemented without using any other gate. Using only NOR gates or only NAND gates all other Boolean expressions can be created unlike other gates. In this article, we will discuss the difference between NAND GATE and NOR GATE.  Table of Content What is NAND Gate
4 min read
Insulated Gate Bipolar Transistor
IGBT stands for Insulated Gate Bipolar Transistor. IGBTs find extensive applications in various domains, including household appliances like air conditioners and refrigerators, industrial motors, and automotive main motor controllers. Their utilization of these devices serves to enhance overall energy efficiency. IGBT is also called insulated gates
11 min read
Implementation of NAND Gate using 2 : 1 MUX
In electronics Engineering, Understanding the Concepts of MUX and Logic gates is very important. These components are the building blocks for designing and Constructing complex digital circuits. Multiplexer is a versatile device that plays an important role in data routing and Selection. It enables the selection of one of the several input signals
6 min read
Digital Logic and Design - GATE CSE Previous Year Questions
Solving GATE Previous Year's Questions (PYQs) not only clears the concepts but also helps to gain flexibility, speed, accuracy, and understanding of the level of questions generally asked in the GATE exam, and that eventually helps you to gain good marks in the examination. Previous Year Questions help a candidate practice and revise for GATE, whic
4 min read
NOR Gate
Logic gates are one of the most important elements of digital electronics engineering. It works on the concept of Boolean function. There are several gates in digital electronics, NOR Gate is one of them, which also lies under the Universal Gate because it can be used to implement other basic logic gates like AND, OR, and NOT gate by connecting NOR
7 min read
NOT Gate
This article will explain the concept of NOT gate operation in digital electronics along with its truth table, logic symbol, switching circuit diagram, etc. The NOT gate is one of the main building blocks of Digital Logic Circuits. A NOT Gate, also called an inverter, has only one input and one output. It is a logic gate whose output is always the
8 min read
AND Gate
Logic gates are small digital switching circuit that determines the output of two or more inputted functions in Binary format. Logical '1' means 'True' or 'High' in nature, whereas logical '0' means 'False' or 'Low' in nature. Based on different logical operations, the output differs. There can be many inputs in a logic gate but there will be only
6 min read
Implementation of NOR gate using 2 : 1 Mux
In Digital Electronics, the concepts of Gates and Mux are a must to design the Digital circuit. The gates are the building block in Digital electronics and a MUX is a combinational logic circuit used in Digital Electronics. By Combining different types of gates we can design a complex circuit that can be used to perform a specific task. Through a c
6 min read
Implementation of AND gate using 2 : 1 Mux
In Digital Electronics, The concept of the Gates and Multiplexer is Important for Building any Digital Logical Circuit. The Gates are the Building Block of the Digital Electronics. On the Other hand, Multiplexers are an Important Component in Digital Electronics. They Enable the Selection of one data input from the Multiple Lines. Together, These T
5 min read
CMOS Logic Gate
The logic gates are the basic building blocks of all digital circuits and computers. These logic gates are implemented using transistors called MOSFETs. A MOSFET transistor is a voltage-controlled switch. The MOSFET acts as a switch and turns on or off depending on whether the voltage on it is either high or low. There are two types of MOSFETs: NMO
4 min read
XNOR Gate
In digital electronics, the XNOR gate is a type of logic gate used to perform an exclusive NOR gate. It is a special type of logic gate used in digital circuits. An XNOR gate, also known as an equivalence gate or an EX-NOR gate, is a digital logic gate that outputs true (1) when an even number of true inputs are present. It produces a true output i
10 min read
OR Gate
The OR gate is known as a primitive digital electronics building block in digital logic. This is one of the logic gates that executes the logical disjunction—a function producing true when at least one input is true. OR gates can be used in applications in digital circuits, computer systems, and other electronic devices. They form the basis of deci
9 min read
NAND Gate
Logic Gates are one of the most important topics in electronics, especially digital electronics. The concept of logic gates relies on the concept of Boolean functions. Logic gates take one or multiple binary values as input and return one binary value as output after doing the logical calculation on them. There are several kinds of GATEs available
7 min read
Implementing Any Circuit Using NAND Gate Only
A universal gate is such a gate that we can implement any Boolean function, no matter how complex, using a circuit that consists of only that particular universal gate. The NAND & NOR gates are the most commonly encountered universal gates in digital logic. In this article, we will take a look at how to convert any circuit into a circuit that c
8 min read
Realization of Logic Gate Using Universal gates
In Boolean Algebra, the NAND and NOR gates are called universal gates because any digital circuit can be implemented by using any one of these two i.e. any logic gate can be created using NAND or NOR gates only. Every logic gate has a representation symbol. The below image shows a graphical representation of all logic gates.  Implementation of AND
7 min read
Program for Decimal to Binary Conversion
Given a decimal number as input, we need to write a program to convert the given decimal number into an equivalent binary number. Examples of Decimal to Binary:  Input : 7Output : 111Input : 10Output : 1010Input: 33Output: 100001Recommended PracticeDecimal to binaryTry It!Brute force ApproachFor Example: If the decimal number is 10. Step 1: Remaind
15+ min read