There are three Boolean operators: AND, OR and NOT. These operators are written differently depending on the language being used. In mathematics, the logical operators are written as
The following table compares how AND OR and NOT are written in different programming languages:
Language | AND | OR | NOT |
---|---|---|---|
Mathematics | |||
“C” or C++ | && | || | ! |
SQL | AND | OR | NOT |
Pascal | AND | OR | NOT |
Perl | & | || | ! |
Java | & | || | ! |
Basic | AND | OR | NOT |
The Boolean operators are evaluated in the following fashion. For the AND operator, the combination of two “True” values results in “True” all other combinations evaluate to False. For example:
True AND True evaluates to True
True AND False evaluates to False
False AND True evaluates to False
False AND False evaluates to False
True AND True evaluates to True
True AND False evaluates to False
False AND True evaluates to False
False AND False evaluates to False
For the OR operator, as long as one of the value is True, then the expression evaluates to True:
True OR True evaluates to True
True OR False evaluates to True
False OR True evaluates to True
False OR False evaluates to False
True OR True evaluates to True
True OR False evaluates to True
False OR True evaluates to True
False OR False evaluates to False
The NOT operator is called the “complimentary” operator. It reverses the truth value of the operand:
NOT True evaluates to False
NOT False evaluates to True.
NOT True evaluates to False
NOT False evaluates to True.
The Boolean operators and their evaluations are often expressed in Truth Tables. We write T and F to signify the values of True and False respectively. The following are truth tables for the three operators:
|
|
|
To use a truth table, choose a value from a row on the top and from a column on the left side and then see where they intersect to determine what they evaluate to. For example, looking at the truth table for AND, pick the value F for False on the top and then pick the value T for True along the left side. Where these two intersect shows an F for False meaning True AND False evaluates to False.