Computers use electrical circuits which have two states – on or off. This can also be represented as 1 or 0 or True and False.
Logic gates take an input of True or False and give an output of True or False. Each operator has a standard symbol that can be used when drawing logic gate circuits.
The three main logic gates are: AND, OR and NOT.
AND gate
In an AND gate, both inputs need to be 1 for the output to be 1.
If input A AND Input B are true then output (Q) will be true. This can be seen in the truth table for the AND gate. The Boolean expression is written as Q = A AND B.
Input A
Input B
Output Q
0
0
0
0
1
0
1
0
0
1
1
1
Input A
0
Input B
0
Output Q
0
Input A
0
Input B
1
Output Q
0
Input A
1
Input B
0
Output Q
0
Input A
1
Input B
1
Output Q
1
OR gate
In an OR gate, at least one input must be 1 for the output to be 1. This can be seen in the truth table for the OR gate.
If input A OR input B is true, then output (Q) will be true. The Boolean expression is written as Q = A OR B.
Input A
Input B
Output Q
0
0
0
0
1
1
1
0
1
1
1
1
Input A
0
Input B
0
Output Q
0
Input A
0
Input B
1
Output Q
1
Input A
1
Input B
0
Output Q
1
Input A
1
Input B
1
Output Q
1
NOT gate
A NOT gate is also known as an inverter as it inverts the input. The output is always the opposite of the input.
This can be seen in the truth table below. If input A is true then output Q is NOT true, if input A is false then output Q will NOT be false (i.e., true). The Boolean expression is Q = NOT A.