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:
Computers can perform the following 'logical' comparisons:
The tables below use a 1 (one) to represent TRUE, and use 0 (zero) as FALSE
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.
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.
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!
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.
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.