Computer Science 101 The Boolean System
George Boole British mathematician ( ) Boolean algebra –Logic –Set theory –Circuits –Conditions in if statements and while loops
Boolean Constants and Variables Just two constants –True and False –On and Off –5v and 0v –1 and 0 Boolean variables refer to these values
Boolean Operators Just three –AND –OR –NOT AND and OR are binary operators (like + and *) NOT is a unary operator
Boolean AND If A and B are Boolean variables (or expressions), then A AND B is True if and only if both A and B are True AND is sometimes written like multiplication in ordinary algebra: A AND B = AB or A. B
Truth Table for AND There are a finite number of possible values of A AND B We can specify these in a truth table ABA AND B True False TrueFalse
Boolean OR If A and B are Boolean variables (or expressions), then A OR B is True if and only if at least one of A and B is True OR is sometimes written like addition in ordinary algebra: A OR B = A + B
Truth Table for OR There are a finite number of possible values of A OR B We can specify these in a truth table ABA OR B True FalseTrue FalseTrue False
Boolean NOT If A is Boolean a variable (or expression), then NOT A has the opposite value of A NOT is sometimes written as a ~ (tilde) symbol: NOT A = ~A _ Or with a horizontal bar over the variable: A
Truth Table for NOT There are a finite number of possible values of NOT A We can specify these in a truth table ANOT A TrueFalse True
Boolean Expressions Constructed like arithmetic expressions NOT has a higher precedence than AND, which has a higher precedence than OR Parentheses can be used to override precedence or for clarity
Evaluating Boolean Expressions As in arithmetic, replace variables with values and apply the operators Let A be True and B be False Evaluate: A AND NOT (A OR B)
Evaluating Boolean Expressions As in arithmetic, replace variables with values and apply the operators Let A be True and B be False Evaluate: A AND NOT (A OR B) = True AND NOT (True OR False)
Evaluating Boolean Expressions As in arithmetic, replace variables with values and apply the operators Let A be True and B be False Evaluate: A AND NOT (A OR B) = True AND NOT (True OR False) = True AND NOT True
Evaluating Boolean Expressions As in arithmetic, replace variables with values and apply the operators Let A be True and B be False Evaluate: A AND NOT (A OR B) = True AND NOT (True OR False) = True AND NOT True = True AND False
Evaluating Boolean Expressions As in arithmetic, replace variables with values and apply the operators Let A be True and B be False Evaluate: A AND NOT (A OR B) = True AND NOT (True OR False) = True AND NOT True = True AND False = False
Constructing Truth Tables A truth table gives all of the possible values of a Boolean expression Construct a truth table for A AND NOT (A OR B) ABA OR BNOT (A OR B)A AND NOT (A OR B) True False TrueFalseTrueFalse True False TrueFalse
Constructing Truth Tables If there are N variables, there are 2 N rows in the table Best to use 0 and 1 and count in binary to fill in the inputs Construct a truth table for A AND NOT (B OR C) ABCB OR CNOT (B OR C)A AND NOT (B OR C)