NAND and NOR logic gate

Logic Gate

Share

In this tutorial we will learn about NAND and NOR logic gates

Logic Gate: NAND

A NAND gate is a combination of an AND gate and a NOT gate.



The logic gate NAND takes two or more input and works as per the following truth table.


i.e., if both the input A and B are 1 or TRUE then the output is 1 or TRUE; otherwise it is 0 or FALSE

NAND in code

We create a NAND using && and ! in programming language like C, C++, Java, JavaScript, Php etc. So, if we are given an if-statement then the code inside the if block will not be executed if both the variables (expression) are true.


//javascript
var A = true;
var B = true;
if(!(A && B)) {
    console.log("Hello");
} else {
    console.log("Bye");
}

The given code will print Bye, as both A and B are true.

i.e., A && B
= true && true
= true
and !true = false

Logic Gate: NOR

A NOR gate is a combination of an OR gate and a NOT gate.



The logic gate NOR takes two or more input and works as per the following truth table.


i.e., if both the input A and B are 0 or FALSE then the output is 1 or TRUE otherwise it is 0 or FALSE.

NOR in code

We create a NOR using || and ! in programming language like C, C++, Java, JavaScript, Php etc. So, if we are given an if-statement then the code inside the if block will be executed if both the variables (expression) are false.


//javascript
var A = false;
var B = false;
if(!(A || B)) {
    console.log("Hello");
} else {
    console.log("Bye");
}

The given code will print Hello as both A and B are false.

i.e., A || B
= false || false
= false
and !false = true

Recently Added