590 likes | 781 Views
Boolean Logic and Circuits. Professor James T. Williams, Jr. HONP112 Week 2 Lesson. George Boole (1815-1864). George Boole developed the mathematics that made modern computing possible, almost a century before the first computers were actually developed. . Boolean Logic.
E N D
Boolean Logic and Circuits Professor James T. Williams, Jr. HONP112 Week 2 Lesson
George Boole (1815-1864) • George Boole developed the mathematics that made modern computing possible, almost a century before the first computers were actually developed.
Boolean Logic • A special kind of mathematics where there are only 2 possible values. • These values are true and false. • Special operators are used with these values to create expressions. • A boolean expression will evaluate to either true or false in its entirety.
Boolean Operators • There are three Boolean operators: • AND • OR • NOT
Order of Operations • First, any expression in parenthesis • Then the AND • Then the OR
The AND Operator • The AND operator is a BINARY operator (i.e. it acts on two variables or expressions – “binary” in this context does not mean “base-2”) • Example expression: A AND B • Also can be written as A * B • The resulting value of the expression depends on the values of A and B.
Evaluating AND expressions • An AND expression only evaluates to true if BOTH of the sub-expressions also evaluate to true. Otherwise, it evaluates to false. • false AND false = false • false AND true = false • true AND false = false • true AND true = true
AND – Truth Table • We can look at all the possibilities for the value of A*B as a truth table:
AND - Example • Assume: A is true and B is false • What does the expression A * B evaluate to? • What if A is true and B is true?
AND – More examples • Assume: A is true, B is false, C is true, D is true • What does the expression A * B evaluate to? • What does the expression C * D evaluate to? • What does (A*B) * (C*D) evaluate to?
The OR Operator • The OR operator is a BINARY operator (i.e. it acts on two variables or expressions) • Example expression: A OR B • Also can be written as A +B (Careful – the plus sign does not mean “and”!!) • The resulting value of the expression depends on the values of A and B.
Evaluating OR expressions • An OR expression only evaluates to true if EITHER of the sub-expressions also evaluate to true. Otherwise, it evaluates to false. • false OR false = false • false OR true = true • true OR false = true • true OR true = true
OR – Truth Table • We can look at all the possibilities for the value of A+B as a truth table:
OR - Example • Assume: A is true and B is false • What does the expression A + B evaluate to? • What if A is true and B is true? • What if A is false and B is false?
OR – More examples • Assume: A is true, B is false, C is true, D is true • What does the expression A + B evaluate to? • What does the expression C + D evaluate to? • What does (A+B) + (C+D) evaluate to?
The NOT Operator • The NOT operator is a UNARY operator (i.e. it acts on one variable or expressions) • Example expression: NOT A • Also can be written as -A • The resulting value of the expression depends on the value of A
Evaluating NOT expressions • An NOT expression simply evaluates to the inverse value of the expression. • NOT false = true • NOT true = false
NOT – Truth Table • We can look at all the possibilities for the value of -A as a truth table:
NOT - Example • Assume: A is true and B is false • What does the expression -A evaluate to? • What does the expression -B evaluate to?
Evaluating Boolean Expressions • Consider (B AND NOT A) OR (NOT D OR C). • Assume A=1, B=1, C=1, and D=0 • Put in the variable values and simplify as below: • (1 AND NOT 1) OR (NOT 0 OR 1) • (1 AND 0) OR (1 OR 1) • 0 OR 1 • 1
More Boolean Expressions • Some more examples to work out in class or on your own time. Remember the order of operations. • Assume A=1, B=1, C=1, and D=0 • A OR D AND B = x • (NOT B AND C) AND (A OR C) = x • (B AND NOT D OR C) OR (NOT B AND B) = x • (A AND B AND C) OR (B AND D) = x • (A*B*C) + (B*D) = x [alt. version of above]
What does this have to do with computers? • All computer/digital circuits are constructed from various combinations of Boolean expressions. • These are implemented in the computer by very tiny electronic components, built into chips, called “gates.” • Depending on the values going into the gates, the end result will be either a logical 0 or 1. This corresponds with false or true.
Technically speaking… • The gates in a computer understand the state 0 or 1 based on electrical voltage. • Very generally speaking, for our purposes only, a 1 is about 5 volts, and a 0 is 0 volts or close to it. • In real life these values may vary, but the idea is the same. • It is more accurate to refer to the 1 and 0 in computer circuits as “high” or “low”.
The Logisim simulator • In case you wonder where the following screen shots are coming from... • There is a free logic circuit simulator called Logisim. • http://ozark.hendrix.edu/~burch/logisim/ • Dark green is low, bright green is high • Let’s see what happens with our logic gates.
The AND gate • The AND gate is represented using the symbol below. • It takes two inputs and produces a single output. For the output to be high, both inputs must be high.
The AND gate • Let’s change one of the inputs to high. • Because both are not high, the output is still low.
The AND gate • Now let’s make both inputs high. • Notice that now the output is high.
The OR gate • The OR gate is represented using the symbol below. • It takes two inputs and produces a single output. For the output to be high, only one of the inputs must be high.
The OR gate • Let’s change one of the inputs to high. • Notice that the output went high just by making one of the inputs high.
The NOT gate • The symbol below represents the NOT gate. This is also called an “inverter.” • Notice that the output is high when the input is low.
The NOT gate • Changing the input to high makes the output low.
Consider This Boolean Expression • (A AND NOT B) OR (C OR D) = x • What is x? It depends on the values assigned to A, B, C, and D. • Remember the values can only be true or false.
Our Example as a Circuit • (A AND NOT B) OR (C OR D) = x • Assume A=true, B=false, C = false, D=true.
Let’s make a change • (A AND NOT B) OR (C OR D) = x • Assume A=false, B=false, C = false, D=true.
Let’s make another change • (A AND NOT B) OR (C OR D) = x • Assume A=false, B=true, C = false, D=false.
Some more examples … • Maybe in class, or on your own time … try to visualize them as circuits this time around. • (A AND NOT B) AND (C OR D) • (A * -B) * (C + D) [alt. version of above] • (D + -B + C) * C • -A * B * (C + A) • Substitute different values for the variables. • Try some with more or less variables. Experiment. Learn by doing.
Special Gates • In circuit design, there are some special gates that are commonly used. • The purpose of these gates is to make circuits simpler to build (less hardware = less effort = less cost). • The gates we will discuss are not standard boolean operators, but are actually single circuits constructed from the standard boolean gates.
Three Special Gates • NAND: “Not And” (AND gate followed by a NOT gate) • NOR: “Not Or” (OR gate followed by a NOT gate) • XOR: “Exclusive OR” (means that you only get a high output if EITHER of the inputs is high, not both. The circuit for XOR is more complex than for NAND or NOR)
The NAND gate • Same as AND followed by a NOT. Notice that we only draw the bubble part of the NOT gate on a NAND symbol (short-cut)
The NOR gate • Same as OR followed by a NOT. Notice that we only draw the bubble part of the NOT gate on a NOR symbol (short-cut)
The XOR gate • This means that only one of the two inputs can be high to get a high output. Notice how XOR symbols are drawn, and see the two simulations below. (The XOR circuit itself is not shown).
NAND – Truth Table • Remember our earlier AND truth table. Just invert the output values and that is the NAND truth table. • Let’s use 1 and 0 to represent true/high and false/low.
NOR – Truth Table • Remember our earlier OR truth table. Just invert the output values and that is the NOR truth table. • Let’s use 1 and 0 to represent true/high and false/low.
XOR – Truth Table • Remember our earlier OR truth table. XOR is the same except that we get low when both inputs are high. • Let’s use 1 and 0 to represent true/high and false/low.
Let’s stop and review • Know the truth tables for the six gates we have discussed. • Know the various ways to represent the logical values of true/false. • Be able to evaluate a boolean expression using the three simple operators. • Be able to evaluate a circuit using any of the six logic gates.
Boolean circuits in action… • At this point, trying to imagine what the computer can do with these types of circuits may be a bit abstract. • So let’s look at a concrete example of a real circuit that is used by every computer. • You will not have to memorize this circuit but hopefully it will help illustrate a real-life application of a boolean logic circuit.
This is a real circuit • This circuit (a “full adder”) is used by computers to add one column of two whole numbers (in base-2 of course). • Again … You do not have to memorize this circuit, but just try to understand what it does.
The Full Adder - analysis • Imagine you are adding a single column of numbers. • Notice there are three inputs. These are the first addend, the second addend, and the current value of the carry. • There are two outputs. One is the result value that gets placed in the result column, and the other is the new carry value. • We already know the addition algorithm … so let’s test the circuit to make sure it works correctly. • Important: in the following slides, the “+” symbol will mean “plus” !
Full adder – one test • Assume the carry is 0, the first addend is 1, the second addend is 0. • 0+1+0 = 1. 1 is not >= the base, so we set the result to 1, and the carry stays zero.
Full adder – another test • Now, assume the carry is 0, the first addend is 1, the second addend is also 1. • 0+1+1= 2. 2 is >= the base, so we subtract the base from the result, and set the carry to 1.