A computer is capable of logic, or what we humans might call primitive 'reasoning'. Using logic, a computer can compare values, and make decisions based on that comparison. Programmers use this 'logic' to write programs.

To describe how each logical function works, a 'truth table' is used to show how two pieces of information when run through the logic function create a specific output pattern. A one ( '1' ) represents 'true' and a zero ( '0' ) represents 'false'. When two inputs (binary values) are combined with logical functions, you get a very specific output pattern.

## COMPUTER LOGIC FUNCTIONS

The computer understands the following:

- TRUE
- FALSE

Computers can perform the following 'logical' comparisons:

- AND
- OR
- NOT

The tables below use a 1 (one) to represent **TRUE**, and use 0 (zero) as **FALSE**

### AND

**AND** is represented mathematically by the ( ^ ) symbol.
It produces a 'true' result whenever you have 'true' on both inputs. AND is
the function used compare IP
addresses with masks. This is the critical logic function to understand
for networking.

0 | 1 | |

0 | 0 | 0 |

1 | 0 | 1 |

I will give you a real-world example of when you would use an AND function. Let's say a programmer wants a drink machine to distribute a drink when both of the following conditions are true:

- The user has inserted the correct ammount of money.
- The user has pressed a selection button.

If both conditions are true, then the coke machine should distribute the drink of the user's choice. The check of condition one (correct payment?) against condition two (drink selected?) would be called an 'AND' function. The money AND the selection conditions must be true to distribute a drink.

### OR

**OR** is represented mathematically by the ( V ) symbol.
OR produces a 'true' result when you have a 'true' on either or both inputs.

0 | 1 | |

0 | 0 | 1 |

1 | 1 | 1 |

Let's use our 'drink machine' example again. The OR function would be used
to see if a button was pressed: Coke **or ** 7-Up. Eigher of them meets
the drink selection criteria, but that leaves us with a problem. According
to the table above, pressing both buttons gets us both drinks! You could press
two buttons and get two sodas if we used the OR function. We need a better
solution!

### XOR

**XOR** (eXclusive OR) is represented mathematically
by the symbol ( ).
Whenever you have a 'false' on one input, and a 'true' on the other input,
a 'true' result is generated.

0 | 1 | |

0 | 0 | 1 |

1 | 1 | 0 |

This is the function we really should use to check our drink selection on our drink machine. The user can press only ONE drink selection, and not any of the others at the same time. The user can exclusively select Coke or 7-up, but not both, thereby selecting one and only one drink.

**NEGATIVE LOGIC FUNCTIONS**

Often, it's easier to watch for the exception to the rule, rather than try to watch for all the occurrances of the result you want. Negative logic helps in those cases. The output of these logical functions are the 'inverse' of the normal logical functions. You should be aware of them, but you only need to understand and use them if you intend to be designing computer chips or writing computer programs.

### NAND

**NAND** ( 'Negative AND' ) Negative AND is the 'inverse'
of the AND function. When you have two false inputs, you get a true result.
Compare the table below to the AND table above.

0 | 1 | |

0 | 1 | 1 |

1 | 1 | 0 |

### NOR

**NOR** ('Negative OR') Negative OR is the 'inverse'
of the OR function. When you have a 'false' input on one or both inputs, you
get 'true' as the result. Compare the NOR table below to the OR table above.

0 | 1 | |

0 | 1 | 0 |

1 | 0 | 0 |

<< < 1 | 2 | 3 | 4 | **5** | 6 | 7 > >>

**Bookmark this page and SHARE:**