Logical operation

Updated: 06/27/2017 by Computer Hope

Circuit diagram of an OR gate created only with NAND gatesA logical operation is a special symbol or word which connects two or more phrases of information. It is most often used to test whether a certain relationship between the phrases is true or false.

In computing, logical operations are necessary because they can be used to model the way that information flows through electrical circuits, such as the circuits inside a CPU. These types of operations are called Boolean operations.

The elements in a circuit which behave according to Boolean logic are called logic gates.

Fundamental logic operations

The following seven logic operations take inputs that are either true (1) or false (0) and produce a single output value that is also true or false.

Most of these operations can take more than two inputs, except for the NOT operation which takes only one input. Below are examples using only one or two inputs, which is what usually happens inside a computer.

The operations are:

AND

The AND logic operation returns true only if all of its inputs are true. If any of the inputs is false, the output is also false.

In computer programming, the AND operation is usually written as && (two ampersands).

In Boolean algebra, the AND operation of two inputs A and B can be written as AB.

Below is the truth table for a two-input AND operation, and the circuit diagram of an AND logic gate.

AND logic gate circuit diagram
AND

A

B

AB
0 0 0
1 0 0
0 1 0
1 1 1

OR

The OR logic operation returns true if any of its inputs are true. If all of the inputs are false, the output is also false.

In computer programming, the OR operation is usually written as || (two vertical bars).

In Boolean algebra, the OR value of two inputs A and B can be written as A+B.

Note: Do not mistake the OR operation for arithmetic addition, even though they both use the "+" symbol. They are distinct operations.

Below is the truth table for a two-input OR operation, and the circuit diagram of an OR logic gate.

OR logic gate circuit diagram
OR

A

B

A+B
0 0 0
1 0 1
0 1 1
1 1 1

NOT

The NOT logic operation returns true if its input is false, and false if its input is true.

In computer programming, the NOT operation is usually written as ! (an exclamation mark).

In Boolean algebra, the NOT value of an input A can be written as (A with an overscore).

Below is the truth table for a NOT operation, and the circuit diagram of a NOT logic gate.

NOT logic gate circuit diagram
NOT

A

0 1
1 0

NAND

The NAND logic operation (which stands for "NOT AND") returns true if any of its inputs are false, and false if all of its inputs are true.

In Boolean algebra, the NAND value of two inputs A and B can be written as AB overscore (AB with an overscore).

NAND has the distinction of being one of two "universal" logic gates because any other logic operation can be created using only NAND gates. (The other universal logic gate is NOR.)

Below is the truth table for a two-input NAND operation, and the circuit diagram of a NAND logic gate.

NAND logic gate circuit diagram
NAND

A

B
___
AB
0 0 1
1 0 1
0 1 1
1 1 0

NOR

The NOR logic operation (which stands for "NOT OR") returns true if all of its inputs are false, and false if any of its inputs are true.

In Boolean algebra, the NOR value of two inputs A and B can be written as A plus B, overscore (A+B with an overscore).

NOR has the distinction of being one of two "universal" logic gates, because any other logic operation can be created using only NOR gates. (The other universal logic gate is NAND.)

Below is the truth table for a two-input NOR operation, and the circuit diagram of a NOR logic gate.

NOR logic gate circuit diagram
NOR

A

B
_____
A+B
0 0 1
1 0 0
0 1 0
1 1 0

XOR

The XOR logic operation (which stands for "Exclusive OR" returns true if any of its inputs differ, and false if they are all the same. In other words, if its inputs are a combination of true and false, the output of XOR is true. If its inputs are all true or all false, the output of XOR is false.

In Boolean algebra, the XOR value of two inputs A and B can be written as A⊕B. (The XOR symbol, ⊕, resembles a plus sign inside a circle.)

Below is the truth table for a two-input XOR operation, and its circuit diagram:

XOR logic gate circuit diagram
XOR

A

B

A⊕B
0 0 0
1 0 1
0 1 1
1 1 0

XNOR

The XNOR logic operation (which stands for "Exclusive NOT OR" returns true if all of its inputs are the same, and false if any of them differ. In other words, if its inputs are a combination of true and false, the output of XNOR is false. If its inputs are all true or all false, the output of XNOR is true.

In Boolean algebra, the XNOR value of two inputs A and B can be written as A circle-plus B, overscore.

Below is the truth table for a two-input XNOR operation, and its circuit diagram:

XNOR logic gate circuit diagram
XNOR

A

B
_____
A⊕B
0 0 1
1 0 0
0 1 0
1 1 1

Boolean, Operator, Programming terms