# Logic Gates

**Logic Gates**: In this tutorial, we are going to learn about the **logic gates** like **AND Gate, OR Gate, NOT Gate, Exclusive-Or Gate/XOR Gate, and Exclusive-NOR Gate/XNOR Gate**.

Submitted by Saurabh Gupta, on November 13, 2019

**Logic Gates** are the fundamental building blocks of a digital system. The name Logic Gates has been derived from the fact that the device should be able to make decisions on its own. It should be able to distinguish different output levels, for example, one output level is produced when some level of input is present and other output level is produced when another set of input is provided.

Input and Output of logic gates occur in only two states either ON/High/True or OFF/Low/False. We simply represent these in numerical form as 1 and 0 respectively.

A Truth Table contains all possible combinations of inputs and their possible outputs. It shows how the logic circuit's output responds to various combinations of logic levels at the inputs.

There are just three basic types of gates - **AND Gate**, **OR Gate**, and **NOT Gate**. Additionally, we have two more gates namely, **XOR Gate** and **XNOR Gate**.

### 1) AND Gate

An **AND Gate** may have two or more inputs. The output of **AND Gate** will be 1 when all of its inputs are in state 1. The output will be in 0 states if even any one of its inputs is in state 0. Logic operation of **AND Gate** is given as **Y= A.B**.

**Symbol and Truth table for AND Gate:**

### 2) OR Gate

An **OR Gate** may also have two or more inputs. The output of **OR Gate** will be 1 when any of its inputs are in state 1. The output will be in 0 state, if all of its inputs are in state 0. Logic operation of **OR Gate** is given as **Y = A+B**.

### 3) NOT Gate

A **NOT Gate** is used for complementing the input provided. If the input will be high then output will be low and vice-versa. Logic operation of **NOT Gate** is given as: **Y=A'/A** (provided A is the input) which is read as A compliment.

**Symbol and Truth table for NOT Gate:**

### 4) Exclusive-Or Gate/XOR Gate

An **XOR Gate** has two inputs. The output of **XOR Gate** will be 1 when and only one of its inputs is provided high state (1). The output will be in 0 state, if both of its inputs are in logic state 0 or logic state 1. Logic operation of **XOR Gate** is given as: **Y= AB + AB = A⊕B**.

### 5) Exclusive-NOR Gate/XNOR Gate

An **XNOR Gate** has two inputs. The output of **XNOR Gate** will be 1 when and when both of its inputs are provided either low state (0) or high state (1). The output will be in 0 state, when one of its inputs is in logic state 0 and another in logic state 1. Logic operation of **XNOR Gate** is given as **Y= AB + AB = A⨀B**.

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions