Boolean Algebra was invented by nineteenth century mathematician George Boole. In Boolean Algebra, mathematical expressions are evaluated to one of two values: True or False. Boolean logic is the mathematical logic that is fundamental to Boolean Algebra.
Boolean logic is used throughout computer science. Understanding how to pose and evaluate Boolean logic expressions is a crucial skill for any programmer or indeed anyone who programs computers in a formal language (such as “C”, C++, Java, Pascal, Fortran, SQL, etc.) or in a macro language such as shell scripts or MS Excel formulas and macros.
This primer endeavors to introduce the topic of Boolean logic and demonstrates how it is used in a variety of situations.
Boolean logic is called a Two Valued Logic because an expression may only take on one of two values: True or False. An expression is some collection of logical operands and logical operators that are combined together.
In arithmetic, the operands are numbers and the operators are the familiar addition, subtraction, multiplication and division. In Boolean logic, the operands are statements (that can be proven True or False) and the operators are logical AND, OR and NOT.
For example consider this expression: 4 < 6
clearly this expression is True since the number four is less than the number 6.
clearly this expression is True since the number four is less than the number 6.
As another example, consider the following statement:
I am 6 feet tall AND I am president of the United States
I am 6 feet tall AND I am president of the United States
While it may be True that I am six feet tall (a fact that can be proven by measuring my height), it can certainly be shown that I am not the president of the United States. Therefore, according to Boolean logic, this entire sentence is False. Another way of saying this is: It is False that I am 6 feet tall AND I am the president of the United States.
Consider a similar sentence:
I am 6 feet tall OR I am president of the United States
I am 6 feet tall OR I am president of the United States
Notice in this case that only one of the parts of the sentence (separated by OR) need be True in order for the entire sentence to be considered True. Another way of saying this is: It is True that I am 6 feet tall OR I am the president of the United States.