Wikipedia
Link :: Logic Goats (Google Video)
A mathematician called Boole invented a branch of maths for processing true and false values instead of numbers. This is called Boolean Algebra. Simple Boolean algebra is consistent with common sense but if you need to process decisions involving many values that might be true or false according to complex rules, you need this branch of mathematics.
There are several types of gate. Each follows a very simple set of rules. By combining many gates in suitable ways, processing devices can be produced. A computer CPU chip can have millions of gates fabricated onto it. The table below shows several gates with two inputs. Many of these gates are also available in three, four and eight input versions.
Rule |
Symbol |
Boolean |
One Line Explanation |
AND |
Q = A . B |
1 AND 1 gives 1. Any other input gives 0. |
|
NAND |
Q = A . B |
(NOT AND) 1 AND 1 gives 0. Any other input gives 1. |
|
OR |
Q = A + B |
0 OR 0 gives 0. Any other input gives 1. |
|
NOR |
Q = A + B |
(NOT OR) 0 OR 0 gives 1. Any other input gives 0. |
|
XOR |
Q = A |
Equal inputs give 0. Non equal inputs give 1. |
|
NOT |
Q = A |
Invert input bits. 0 becomes 1. 1 becomes 0. |
Computers work using LOGIC. Displaying graphics such as the mouse cursor involves the XOR (Exclusive OR) opeartion. Addition makes use of AND and XOR. These and a few of the other uses of logic are described below.
The one line descriptions of the rules above are clearer if shown in Truth Tables. These tables show the output for all possible input conditions. The inputs are always listed in the same order (counting in binary starting from zero).
Here is a summary. The yellow highlights match the rules above.
| AND | NAND | OR | NOR | XOR | NOT | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
|
A B Q |
A B Q 0 0 1 0 1 1 1 0 1 1 1 0 |
A B Q 0 0 0 0 1 1 1 0 1 1 1 1 |
A B Q 0 0 1 0 1 0 1 0 0 1 1 0 |
A B Q 0 0 0 0 1 1 1 0 1 1 1 0 |
A Q 0 1 1 0 |
|||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
Two ones |
Two ones |
Two zeros |
Two zeros |
Equal |
Input |
Logic gates are the building blocks of all digital computers. Modern processors contain millions of gates. Each gate is built from a few transistors. The gates are used to store data, perform arithmetic and manipulate bits using the rules above. For example, the XOR rule can be used to test bits for equality.

Both inputs must be true for the output to be true. AND is used for addition, decision making and bit masking.
The AND rule can be used in industrial safety. A sheet metal cutter might require two switches to be pressed before the cutter operates. One switch is is operated when the safety screen is closed. The other operates the cutter. This prevents the operator cutting off his/her arm.
----------- A B Output ----------- 0 0 0 0 1 0 1 0 0 1 1 1

Both inputs must be false for the output to be false. OR is used in decision making and bit masking.
Fire alarm glasses (break to sound the alarm) obey the OR rule. One or more broken glasses cause the alarm to sound.
----------- A B Output ----------- 0 0 0 0 1 1 1 0 1 1 1 1

If the bits in a graphical image are XORed with other bits a new image appears. If the XORing is repeated the image disappears again. This is how the mouse and text cursors get moved around the screen. XOR is combined with AND for use in addition. XOR detects if the inputs are equal or not.
----------- A B Output ----------- 0 0 0 0 1 1 1 0 1 1 1 0

NAND is really AND followed by NOT. Electronic circuits are commonly built from NAND gates (circuits). Computer programming languages generally do not provide NAND. Use NOT AND instead. Gate arrays can be based on NAND gates.
----------- A B Output ----------- 0 0 1 0 1 1 1 0 1 1 1 0

NOR is really OR followed by NOT. Electronic circuits are commonly built from NOR gates (circuits). Computer programming languages generally do not provide NOR. Use NOT OR instead. Gate arrays can be based on NOR gates.
----------- A B Output ----------- 0 0 1 0 1 0 1 0 0 1 1 0

NOT is used to invert bits or True/False values. All the rules above had two inputs and one output. NOT has a single input and output.
----------- A Output ----------- 0 1 1 0
The half adder does binary addition on two bits.
The AND gate computes the carry bit.
The XOR gate computes the sum bit.
0 + 0 = 0, carry 0
0 + 1 = 1, carry 0
1 + 0 = 1, carry 0
1 + 1 = 0, carry 1
------------------ A B SUM CARRY ------------------ 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 1