Logic Gates

Before reading this page you should read the page 'Binary & Hexadecimal'.

The text below is an extract from the article at www.hardwaresecrets.com/article/237/1

See also the Wikipedia article at en.wikipedia.org/wiki/Logic_gate and this article

Logic gates are the basic components in digital electronics. Digital electronics is based on transistor switches which are either ‘on’ or ‘off’. These two states can be used to represent the binary digits 0 and 1, and by stringing several binary digits or ‘bits’ together we can represent any whole number. For example, the binary number 1101 is equivalent to the decimal number 13 (humans like to use decimal numbers because humans sometimes use their ten fingers and thumbs to count with). Before going any further in this text, please make sure you have read my introduction to binary and hexadecimal numbers.

In the text below, a letter, also known as a variable, represents a binary digit. So “A” can be “0” or “1”. So, if A is connected to a switch, A will be “0” when the switch is turned off and “1” when the switch is turned on. A line drawn right above the variable name (or a slash typed in front of the variable name) means that the variable is inverted. S if A = 0 then /A = 1, and if A = 1 then /A = 0. Other symbols are sometimes used in addition to those given on this page. For a fuller list, see HERE.

The diagrams below show gates with only one or two inputs, but it possible to buy gates with more than two inputs or to make them yourself by combining simple gates together (see the article on hardwaresecrets.com). Now that you know the basics, we can introduce you to logic gates.

NOT (Inverter)

As the name implies, an inverter will invert the number entered. If you enter “0”, you will get a “1” on its output, and if you enter a “1”, you will get a “0” on its output. The inverter symbol you can see on Figure 1. An inverter is also known as a NOT gate and its output is Y = /A.

On the truth table below you can see a summary of how this circuit works. Tables like this are called ‘truth tables’ because the words ‘true’ and ‘false’ are taken to be equivalent to the states ‘on’ and ‘off’ or ‘1’ and ‘0’.

On logic circuits, a “o” symbol is a short for inverter. You will see that little circle on the symbols for logic gates like NAND, NOR and XNOR.

AND

As its name implies, an AND logic gate performs an “AND” logic operation. The output of a two-input AND gate is true (or ‘on’ or ‘1’) if input A is true AND input B is true. Looking at the truth table below you will see that the output could also be obtained by multiplying the inputs together, so we represent the AND operation with A·B. You can see its symbol on Figure 2 and its truth table.

Another way to understand AND logic gate: its output will only be at “1” when all its inputs are also at “1”. Otherwise its output will be “0”.

NAND

The “N” letter on NAND stands for NOT, meaning that the NAND logic gate is a NOT AND gate, i.e. an AND gate with an inverter attached. So, its output is the opposite from AND. Its symbol is the same of AND but with a “o” on its output, meaning that the output is inverted. You can build yourself a NAND gate by connecting an AND gate to an inverter.

Another way to understand the NAND logic gate: its output will only be at “0” when all its inputs are also at “1”. Otherwise its output will be “1”.

NAND gates are cheaper to make than most other gates and are therefore widely used. The image at right shows an ‘integrated circuit’ (IC) chip called the 7400 which contains four NAND gates. The chip needs a power supply in order to work so it also has two pins connected to 5 volts and to zero volts (ground).

OR

As its name implies, an OR logic gate performs an “OR” logic operation. The output of a two-input OR gate is true if input A is true OR input B is true (or both). Looking at the truth table below, you can see that the output can be obtained by adding the inputs together, EXCEPT FOR THE LAST LINE (since in binary arithmetic 1+1=11) so we use the symbol ‘+’ to represent the OR gate. So, if A and B are its inputs, at the output we will find A + B.

Another way to understand OR logic gate: its output will be true when any input is true.

NOR

The “N” letter on NOR stands for NOT, meaning that NOR logic gate is an OR gate with an inverter attached. So, its output is the opposite from OR. Its symbol is the same of OR but with a “o” on its output, meaning that the output is inverted. You can build yourself a NOR gate by connecting an OR gate to an inverter.

Another way to understand NOR logic gate: its output will only be at “1” when all its inputs are at “0”. Otherwise its output will be “0”.

XOR

XOR stands for exclusive OR. An XOR gate compares two values and if they are different its output will be “1”. The output of an XOR gate is true if input A is true OR input B is true BUT NOT BOTH (this is excluded, as the name of this gate implies). XOR operation is represented by the symbol ⊕ . So Y = A ⊕ B.

The output is “1” when the inputs have different values.

XNOR

XNOR stands for exclusive NOR and is an XOR gate with its output inverted. (In the opinion of Mr. Ward, a better name for this type of gate would be NXOR since this would show better that it is the inverse of an XOR gate, N-XOR.) So, its output is at “1” when the inputs have the same value and “0” when they are different.

The output is “1” when all its inputs have the same value.