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 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 TransistorWorking 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 Gate from NAND GateXOR 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:
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 GateSay 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:
- 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.
- 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.
- Binary addition and subtraction: It helps in determining sum of each bit and also combine with other logic gates to handle borrow operations.
- 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
JavaScript JSON
JSON (JavaScript Object Notation) is a lightweight data format for storing and exchanging data. It is widely used to send data between a server and a client. JSON is simple, language-independent, and easy to understand. JSON stands for JavaScript Object Notation.It is a lightweight, text-based data
4 min read
jQuery getJSON() Method
In this article, we will learn about the getJSON() method in jQuery, along with understanding their implementation through the example. jQuery is an open-source JavaScript library that simplifies the interactions between an HTML/CSS document, It is widely famous for its philosophy of âWrite less, do
2 min read
JavaScript JSON Parser
JSON (JavaScript Object Notation) is a popular lightweight data exchange format for sending data between a server and a client, or across various systems. JSON data is parsed and interpreted using a software component or library called a JSON parser. Through the JSON parsing process, a JSON string i
3 min read
ES6 Merge Objects
In this article, we are going to learn how to merge two objects in JavaScript. We can merge two JavaScript Objects in ES6 by using the two popular methods. The methods are listed below: Object.assign() methodObject spread syntax method Using Object.assign() method: Using this method, we can merge tw
3 min read
Rename Object Key in JavaScript
In JavaScript, objects are used to store the collection of various data. It is a collection of properties. A property is a "key: value" pair where Keys are known as 'property name' and are used to identify values. Since JavaScript doesn't provide an inbuilt function to rename an object key. So we wi
4 min read
How to Create XML in JavaScript ?
In JavaScript, XML documents can be created using various approaches. You can define elements, attributes, and content to structure the XML data, and then serialize it into a string for use or storage. There are several approaches to creating XML in JavaScript which are as follows: Table of Content
2 min read
Node.js URL.toJSON() Method
The url.toJSON() method in the node.js URL module is used to return the serialized URL of the URL object. The return value of this method is equivalent to the URL.href and url.toString() methods. If an URL object is serialized using JSON.stringify() method then it is called automatically. Syntax: ur
2 min read
Javascript | JSON PHP
JSON stands for the JavaScript Object Notation. It is used to exchanging and storing the data from the web-server. JSON uses the object notation of JavaScript. JavaScript objects can be converted into the JSON and receive JSON format text into the JavaScript objects. Converting the JavaScript object
7 min read
Converting JSON text to JavaScript Object
Pre-requisite: JavaScript JSON JSON (JavaScript Object Notation) is a lightweight data-interchange format. As its name suggests, JSON is derived from the JavaScript programming language, but itâs available for use by many languages including Python, Ruby, PHP, and Java and hence, it can be said as l
3 min read
String in JavaScript
String is used to representing the sequence of characters. They are made up of a list of characters, which is essentially just an "array of characters". It can hold the data and manipulate the data which can be represented in the text form. We can perform different operations on strings like checkin
3 min read
JavaScript JSON parse() Method
The JSON.parse() method is used to convert a JSON string into a JavaScript object. Itâs become important when dealing with data in JSON format, interacting with APIs, or storing data in the browser. It converts a JSON string into a JavaScript object.Throws a SyntaxError if the input string is not va
4 min read
How To Escape Strings in JSON?
JSON (JavaScript Object Notation) is a popular data format that is widely used in APIs, configuration files, and data storage. While JSON is straightforward, handling special characters within strings requires some extra care. Certain characters must be escaped to be valid within a JSON string. Tabl
3 min read
JSON Hijacking
JSON(JavaScript Object Notation) denotes standard text-based-data format . It is widely used to provide a support mechanism between the server and the web application for the transmission of data. JSON Hijacking is a kind of network security attack. In this attack, an attacker targets a system that
2 min read
JavaScript | JSON Arrays
The JSON Arrays is similar to JavaScript Arrays. Syntax of Arrays in JSON Objects: // JSON Arrays Syntax { "name":"Peter parker", "heroName": "Spiderman", "friends" : ["Deadpool", "Hulk", "Wolverine"] } Accessing Array Values: The Array values can be accessed using the index of each element in an Ar
2 min read
JavaScript String with Quotes
Strings are the sequence of characters, symbols, and numbers. In JavaScript, the user can write strings either in 'single quote' or in "double quote". However, both print the same result on the terminal. 'GeeksforGeeks' === "GeeksforGeeks"In some cases, users may need to print some part of the strin
2 min read
How to Create JSON String in JavaScript?
JSON strings are widely used for data interchange between a server and a client, or between different parts of a software system. So converting objects to JSON strings is very important for good client-server communication. Below are the following approaches to creating a JSON string: Table of Conte
2 min read
How to Parse JSON in JavaScript ?
Parse JSON in JavaScript, accepting a JSON string as input and returning a corresponding JavaScript object with two methods, using JSON.parse() for parsing JSON strings directly and employing the fetch API to parse JSON responses from web APIs. These techniques are crucial for seamless data manipula
2 min read
How to Parse XML in JavaScript?
Parsing XML data is important because it allows JavaScript applications to extract structured information from XML documents. We will explore two different approaches to Parse XML in JavaScript. Below are the approaches to parsing XML in JavaScript: Table of Content Using DOM ParserUsing xml2js Libr
2 min read
How to iterate over a JavaScript object ?
Iteration involves looping through the object's properties one by one. Depending on the method used, you can access and manipulate different levels of properties efficiently. Here are several methods. There are many methods to iterate over an object which are discussed below: Table of Content Using
3 min read