Section 5.1 Boolean Algebra Operations
There are only two values,- AND
-
A binary operator; the result is
if and only if both operands are otherwise the result is We will use ‘ ’ to designate the AND operation. It is also common to use the ‘ ’ symbol or simply “AND.” The AND gate operation is shown in Figure 5.1.1 with inputs andFigure 5.1.1. The AND gate acting on two variables, andWe can see from the truth table that the AND operator follows similar rules as multiplication in elementary algebra.
- OR
-
A binary operator; the result is
if at least one of the two operands are otherwise the result is We will use ‘ ’ to designate the OR operation. It is also common to use the ‘ ’ symbol or simply “OR.” The OR gate operation is shown in Figure 5.1.2 with inputs andFigure 5.1.2. The OR gate acting on two variables, andFrom the truth table we can see that the OR operator follows the same rules as addition in elementary algebra except that
in Boolean algebra. Unlike elementary algebra, there is no carry from the OR operation. Since addition of integers can produce a carry, you will see in Section 7.1 that implementing addition requires more than a simple OR gate. - NOT
-
A unary operator; the result is
if the operand is or if the operand is Other names for the NOT operation are complement and invert. We will use to designate the NOT operation. It is also common to use or The NOT gate operation is shown in Figure 5.1.3 with inputFigure 5.1.3. NOT gate acting on one variable, The NOT operation has no analog in elementary algebra. Be careful to notice that inversion of a value in elementary algebra is a division operation, which does not exist in Boolean algebra.
&&
, ||
, and !
to create logical expressions commonly used to control if
and while
statements. When used in expressions, the operators are applied according to the precedence rules in Table 5.1.4. As with elementary algebra, expressions in parentheses are evaluated first, following the precedence rules.
Operation | Symbol | Precedence |
NOT | Highest | |
AND | Middle | |
OR | Lowest |
-
AND and OR are associative:
For Equation (5.1.1):
And for Equation (5.1.2):
-
AND and OR each have an identity value:
-
AND and OR are commutative:
This is easily proved by looking at the second and third rows of the respective truth tables (Figure 5.1.1 and Figure 5.1.2. In elementary algebra, only the addition and multiplication operators are commutative.
-
AND and OR each have an annulment value:
The annulment value for the AND is the same as multiplication in elementary algebra. But addition in elementary algebra does not have an annulment value, while OR in Boolean algebra does.
-
AND and OR each have a complement value:
Complement does not exist in elementary algebra.
-
AND and OR are idempotent:
That is, repeated application of either operator to the same value does not change it. This differs considerably from elementary algebra—repeated application of addition is equivalent to multiplication and repeated application of multiplication is the power operation.
-
AND and OR are distributive:
Going from right to left in Equation (5.1.13) is the very familiar factoring from addition and multiplication in elementary algebra. On the other hand, the operation in Equation (5.1.14) has no analog in elementary algebra. It follows from the idempotency property.
-
NOT shows involution:
This is easily seen in Figure 5.1.3. Again, there is no complement in elementary algebra.
-
DeMorgan's Law is an important expression of the duality between the AND and OR operations:
The validity of DeMorgan's Law can be seen in the following truth tables.
For Equation (5.1.16):
And for Equation (5.1.17):