1
CS1010 Introduction to Computing
Lecture 11
LEARNING GOALS FOR TODAY
• To become familiar with boolean algebra used by the microprocessors.
• To understand the NOT, AND, OR and XOR
WHY BINARY?
• Because this number system is natural to
microprocessor.
• In microprocessor the simplest element is switch, the switch has only two states i.e. ON or OFF.
• Binary number has only two numbers 1 & 0, so there is analogy between the operations of switches and the
binary number system.
INTRODUCTION
• Boolean algebra is useful in designing logic circuits, which are used by the processors.
• Boolean algebra deals with binary number system.
• Logic gates, are used to build up circuits of different types, for performing the necessary arithmetic
operations.
BOOLEAN ALGEBRA
• In mid-1800’s, George Boole, English mathematician, developed an algebra, which simplified manipulation of propositional logic.
• In the year 1938, Claude E. Shannon proposed the use of Boolean algebra in the design of relay switching
circuits.
Fundamentals Concepts in Boolean
Algebra
• Binary variables take on one of two values.
• Logical operators operate on binary values and binary variables.
• Basic logical operators are the logic functions AND, OR
and NOT.
• Logic gates implement logic functions.
BINARY VARIABLES
• Recall that the two binary values have different names:
– True/False – On/Off
– Yes/No
– 1/0
• We use 1 and 0 to denote the two values.
• Variable identifier examples:
LOGICAL OPERATIONS
• The three basic logical operations are:
– AND – OR
– NOT
• AND is denoted by a dot (·)
• OR is denoted by a plus (+)
• NOT is denoted by an overbar ( ¯ ), a single
BOOLEAN OPERATOR PRECEDENCE
▪
The order of evaluation is:
1
.
Parenthese
s
2
.
NO
T
3
.
AND
4
.
OR
▪
Consequence: Parentheses appear
around OR expressions
NOTATION EXAMPLES
• Examples:
– is read “Y is equal to A AND B”
– is read “z is equal to x OR y”
– is read “X is equal to NOT A”
• Note: The statement:
1 + 1 = 2 (read “one plus one equals two”)
is not the same as
1 + 1 = 1 (read “1 or 1 equals 1”).
= A B
Y ⋅
y x
z = +
TRUTH TABLE
• It’s a table in which, we write all possible inputs and for all possible inputs, what are the
outputs.
• The rows in a truth table depends upon, the
variables, we have in a Boolean expression:
– 1 variable, 2¹ = 2 rows
– 2 variables, 2² = 4 rows
EXAMPLES
• Simplify these Boolean expressions by using
truth table:
a) z = (x + y) ׳ b) z = y . (x + y)
c) z = (y . x) + w
SOLUTION
• z = (x + y) ׳x y x + y (x + y) ׳
1 1 1 0
1 0 1 0
0 1 1 0
SOLUTION
• z = y . (x + y)x y x + y y . (x + y)
1 1 1 1
1 0 1 0
0 1 1 1
SOLUTION
• z = (y . x) + wx y w y . x (y . x) + w
1 1 1 1 1
1 1 0 1 1
1 0 1 0 1
1 0 0 0 0
0 1 1 0 1
0 1 0 0 0
0 0 1 0 1
SOLUTION
• F(X, Y, Z) = X Y + Y ZX Y Z X Y Y Y Z F = X Y + Y Z
1 1 1 1 0 0 1
1 1 0 1 0 0 1
1 0 1 0 1 1 1
1 0 0 0 1 0 0
0 1 1 0 0 0 0
0 1 0 0 0 0 0
0 0 1 0 1 1 1
De-Morgan’s Law
• The complement of a sum of variables is equal to the product of the complements of the variables.
o X + Y = X · Y
• The complement of a product of variables is equal to the sum of the complements of the variables.
o X . Y = X + Y
• Proves this theorem by using truth table.
X Y X·Y X+Y X Y X+Y X · Y X·Y X+Y
1 1 1 1 0 0 0 0 0 0
1 0 0 1 0 1 0 0 1 1
0 1 0 1 1 0 0 0 1 1
Double Complement Law
• X = X
• Proof this theorem by using truth table.
X X X
1 0 1
THEOREM
• X . (X + Y) = X · Y
X Y X X+Y X · (X+Y) X·Y
1 1 0 1 1 1
1 0 0 0 0 0
0 1 1 1 0 0
0 0 1 1 0 0
EXAMPLE
• X + X . Y = X + Y
X Y X X.Y X + (X.Y) X+Y
1 1 0 0 1 1
1 0 0 0 1 1
0 1 1 1 1 1
0 0 1 0 0 0
NOT OPERATOR
• The truth table for NOT operation.
• If input is true, the output is false and vice versa.
x x ׳
1 0
AND OPERATOR
• The truth table for AND operation.
• The output is true, if and only if both inputs are
true.
x y x . y
1 1 1
1 0 0
0 1 0
OR OPERATOR
• The truth table for OR operation.
• The output is true, if either of two inputs is true.
x y z = x + y
1 1 1
1 0 1
0 1 1
24
LAWS OF BOOLEAN ALGEBRA
• Commutative Law
for addition and multiplication
• Associative Law
for addition and multiplication
• Distributive Law
Commutative Law
• Commutative Law for Addition
A + B = B + A
• Commutative Law for Multiplication
Associative Law(1)
• Associative Law for Addition
Associative Law(2)
• Associative Law for Multiplication
Distributive Law
• Distributive Law
De-morgan’s Theorems
• First Theorem
Minimization of Boolean Function
Boolean Algebra and Logic Gates 31
• A given Boolean function, the minimization of the number of literals, and the number of terms, will result in a circuit
with less components.
• For Example: Equal Boolean Functions, F1 is more economical.
• F1 = x.y.z + x.y.z + x.y • F1 = x.y + x.z
EXAMPLE
• Simplify the following Boolean function to a minimum number of literals.
A + AB = A
L.H.S
= A + AB Given Statement
= A(1 + B) Factoring
= A . 1 Rule: 1 + B = 1
= A Rule: A . 1 = A
EXAMPLE
• Simplify the following Boolean function to a minimum number of literals.
x . ( x + y )
= x . ( x + y ) Given statement
= x . x + x . y Distributive Law
= 0 + x . y Complement Law
= x . y + 0 Commutative Law
EXAMPLE
• (A + B)(A + C) = A + BC
L.H.S
This rule can be proved as follows:
= (A + B)(A + C) = AA + AC + AB + BC Distributive law
= A + AC + AB + BC Rule: AA = A
= A( 1 + C) + AB + BC Rule: 1 + C = 1
= A. 1 + AB + BC
= A(1 + B) + BC Rule: 1 + B = 1
= A. 1 + BC Rule: A . 1 = A
= A + BC
Simplification using Boolean Algebra
• AB + A(B+C) + B(B+C)
= AB + AB + AC + BB +BC = AB + AC + B + BC
= AB + B + AC + BC = B(A + 1) + AC + BC = B(1) + AC + BC
Simplify: C+ BC
• C + BC Given
= C + ( B + C ) De-morgan’s Law
= (C + C )+ B Associative Law
= 1+B Apply A + A = 1
Simplify: AB( A+B)(B + B)
• AB( A+B)(B + B) Given
= AB( A+B) Apply A + A = 1
= (A +B)( A+B) De-morgan’s law
= A A+AB+B A+BB
= A+AB+B A Apply A.A = A & A.A = 0
= A+A(B+B ) Apply A + A = 1
= A +A Apply A + A = A
Simplify: A( A+B)+(B + AA)(A + B )
• A( A+B)+(B + AA)(A + B)
= AA + AB +(B + A) (A+B)
= AB + BA + BB + AA + AB
= AB + BA+ A+AB
= B(A + A) +A(1 + B)
EXAMPLE
• Apply DeMorgan's theorems to the expressions:
• XYZ
• X + Y + z
• Solution:
XYZ = X + Y + Z
COMPLEMENT OF A FUNCTIONS
•
Use De-Morgan's Theorem:
1. Interchange AND and OR operators
2. Complement each constant and literal
•
Example:
Complement
▪ F = x.y.z + x.y.z
EXAMPLE
F = x.y.z + x.y.z
• Apply De-Morgan’s theorem as many times as necessary, the complements are obtained as follows:
F = x.y.z + x.y.z = (x.y.z).(x.y.z)
EXAMPLE
F = x.(y.z + y.z)
• Apply De-Morgan’s theorem as many times as necessary, the complements are obtained as follows:
LOGIC GATES
• All operations within a computer are carried out by means of combinations of signals passing through standard blocks of built-in circuits. Which are known as gates.
• A logic gate is an electronic circuit, which operates on one or more inputs signals, to produce standard
output signals.
• Computer circuits are built up using combinations of different types of logic gates to perform necessary
AND Gate
• It is an electronic circuit, which generates an output signal 1, only if all inputs are also 1.
• Here two switches A and B are connected in series. It is obvious that the input current will reach the output point, only when both the switches are in ON(1) state.
• Two or more switches connected in series behave as an
AND gate.
AND GATE SYMBOL & BEHAVIOR
x y z = x . y
1 1 1
1 0 0
0 1 0
0 0 0
OR Gate
• It is an electronic circuit, which generates an output signal 1, if any of the input signals is also 1.
• The input current will reach the output, when any one of the two switches are in the ON(1) state. There will be no output when both the switches are in OFF(0) state.
• Two switches A and B are connected in parallel behave as an OR gate.
OR GATE SYMBOL & BEHAVIOR
x y z = x + y
1 1 1
1 0 1
0 1 1
0 0 0
NOT Gate
• It is physical realization of the complementation operation.
• It is an electronic circuit, which generates an output signal, which is reverse of the input signal.
NOT GATE SYMBOL & BEHAVIOR
NOT
x z = x0 1
SWITCHING CIRCUITS
LOGIC CIRCUITS
• The logic gates are seldom used alone, but are used in combinations. They are interconnected to form combinational logic circuits.
• For these logic circuits, the Boolean algebra expression can be derived.
EXAMPLE
• Find the Boolean Expression of the logic circuit
given below:
D = A . (B + C) is the required Boolean expression for the output of given logic circuit.
A
B C
D
A
B + C
EXAMPLE
• Find the logic expression for the output produced by the logic circuit given below:
• = (x + y)(x .y) is the required Boolean expression for the output of given logic circuit.
x + y
x. y
x.
y (x +
EXAMPLE
• Find the Boolean expression for the output of the logic circuit given below:
• Hence, (A + B) . C . D + (A + B) . C . D is the
required Boolean expression.
B A
C
D
A + B
C
D
(A + B) . C . D (A + B) . C . D
Rules to form a COMBINATIONAL
CIRCUIT
1) To combine two inputs we will MUST use any
gate.
2) We can split input and use it for different gates. 3) The output of one gate can be use for input for
other gates.
4) The output of one gate CANNOT be used for
CONVERTING EXPRESSIONS TO LOGIC
CIRCUITS
• The reverse problem of constructing a logic circuit for a Boolean expression is also not difficult.
• Example: Construct a logic circuit for the Boolean expression A . B + C
• The desired logic circuit.
A B C
A . B
EXAMPLE
• Construct a logic circuit for the Boolean expression: (A.B) + (C.D) + (E.F)
• The desired logic circuit is shown above.
A
B A.B A.B C
D E F
C.D
E.F
E.F
EXAMPLE
• Construct a logic circuit for the Boolean expression: (x + y) . (x + z) . (y + z)
• The desired logic circuit is show above.
y
z
x
x + y
x + z
y + z
EXAMPLE
• Construct a logic circuit for the Boolean expression: (x + y + z) . (x + y) . (x + y)
• The desired logic circuit shown above.
y
z
x
v
( x + y + z)
( x + y)
v
( x + y)
SUM OF PRODUCT(SOP)
• The following steps are followed to express a Boolean function in its sum-of-products form:
❖ From the given table, form a term for each
combination of the variables, which produces a 1 in the function.
Exercise:
Draw a circuit for a following
Input/output Table
INPUTS OUTPUT
P Q R S
1 1 1 0
1 1 0 1
1 0 1 0
1 0 0 0
0 1 1 1
0 1 0 0
0 0 1 0
SOLUTION
INPUTS OUTPUT
P Q R S
1 1 1 0
1 1 0 1
1 0 1 0
1 0 0 0
0 1 1 1
0 1 0 0
0 0 1 0
0 0 0 0
P . Q . R
P . Q . R
Sum these two terms:
CIRCUIT DIAGRAM
• Below is the circuit diagram of the Boolean expression:
EXERCISE
• Design a circuit by using Sum OF PRODUCT rule, to take input signals P, Q and R and output is 1 if, and
only if, P and Q have the same value and Q and R have opposite values.
• Solution:
Step1: Draw a table
Boolean Expression is:
INPUTS OUTPUT
P Q R S
1 1 1 0
1 1 0 1
1 0 1 0
1 0 0 0
0 1 1 0
0 1 0 0
0 0 1 1
0 0 0 0
P . Q . R
P . Q . R
CIRCUIT DIAGRAM
• Below is the circuit diagram of the Boolean expression:
(P . Q . R) +(P . Q . R)
v P Q R v v S v
(P . Q . R)
(P . Q . R) Q
R
PRODUCT-OF-SUM (POS)
• Product-Of-Sum (POS) canonical form:Product of terms of entries that evaluate to ‘0’
x y z F term
0 0 0 1
0 0 1 1
0 1 0 0 M2 = (x + y + z)
0 1 1 1
1 0 0 0 M
4 = (x + y + z)
1 0 1 1
1 1 0 0 M
6 = (x + y + z)
1 1 1 1
Focus on the ‘0’ entries
CONVERTING SUM-OF-PRODUCT FORM
• A function that is not in the Sum-of-Products form can be converted to that form by means of a truth table.
x y z F Minterm
0 0 0 1 m0 = x y z
0 0 1 1 m1 = x y z
0 1 0 1 m2 = x y z
0 1 1 0
1 0 0 1 m4 = x y z
1 0 1 1 m5 = x y z
1 1 0 0
1 1 1 0
F = ∑(0, 1, 2, 4, 5) =
m0 + m1 + m2 + m4 + m5 =
x y z + x y z + x y z +
• A function that is not in the Product-of-Sums form can be converted to that form by means of a truth table
x y z F Minterm
0 0 0 1
0 0 1 1
0 1 0 1
0 1 1 0 M3 = (x+y+z)
1 0 0 1
1 0 1 1
1 1 0 0 M
6 = (x+y+z)
1 1 1 0 M7 = (x+y+z)
F = ∏(3, 6, 7) =
M3 · M6 · M7 =
(x+y+z) (x+y+z) (x+y+z)
STANDARD FORMS
• Standard Sum-of-Products (SOP) form: equations are written as an OR of AND terms
• Standard Product-of-Sums (POS) form: equations are written as an AND of OR terms
• Examples:
– SOP:
– POS:
• These “mixed” forms are neither SOP nor POS
B C B A C B
A + +
C · ) C B (A · B)
Standard Sum-of-Products (SOP)
• A Simplification Example:
• Writing the minterm expression:
F = A B C + A B C + A B C + ABC + ABC
• Simplifying:
F = A B C + A (B C + B C + B C + B C) F = A B C + A (B (C + C) + B (C + C)) F = A B C + A (B + B)
F = A B C + A F = A(B C + 1) F = ABC
• Simplified F contains 3 literals compared to 15
AND/OR Two-Level Implementation
• The two implementations for F are shown below
It is quite
Exclusive-OR
• Exclusive-OR, denoted by ⊕ is binary operator, which perform the following Boolean functions:
x ⊕ y ≡ (x + y)(x.y)
Symbolically,
x y x ⊕ y
1 1 0
1 0 1
0 1 1
CIRCUIT DIAGRAM
x+y
x.y x.y
(x+y)(x.y)
• The exclusive-OR have many excellent
characteristics as candidate for logic gates.
• However, they are expensive to construct with
physical components. Usually constructed
internally with other standard gates.
• The exclusive-OR is useful in arithmetic
EXAMPLE
• A two-input, exclusive-OR function.
• Implementation of Exclusive-OR operation with AND/OR/NOT gates.
A
B
C A
B
A . B
A . B
HOW TO ADD BINARY NUMBERS
• Consider adding two 1-bit binary numbers x and
y.
– 0 + 0 = 0
– 0 + 1 = 1
– 1 + 0 = 1
– 1 + 1 = 10
• Carry is x AND y
• Sum is x XOR y
• The circuit to compute this is called a half-adder
x y Carry Sum
0 0 0 0
0 1 0 1
1 0 0 1
THE HALF-ADDER
• Sum = x XOR y
DESIGN OF HALF-ADDER
• Sum = x XOR y = (x + y)(x.y)
• Carry = x AND y = x . y
x + y
x.y x.y
(x + y).(x.y)
USING HALF ADDERS
• We can then use a half-adder to compute the
sum of two Boolean numbers.
1 1 0 0 + 1 1 1 0 0 1 0 ?
HOW TO FIX THIS
• We need to create an adder that can take a carry bit as an additional input.
– Inputs: x, y, carry in
– Outputs: sum, carry out
• This is called a full adder
– SUM: x.y.c + x.y.c + x.y.c + x.y.c = x ⊕ y ⊕ c
– CARRY: x.y.c + x.y.c + x.y.c + x.y.c = x.y + x.c + y.c
– A full-adder can also be implemented with two half-adders and one OR gate.
x y c carry sum
1 1 1 1 1
1 1 0 1 0 1 0 1 1 0 1 0 0 0 1
0 1 1 1 0 0 1 0 0 1
0 0 1 0 1
S = x⊕y⊕c C = (x⊕y).c
• Full-Adder can be Implemented by two
half-adders and one OR gate as shown:
HA
HA
C x
y
c
S = x.y + x.y = x⊕y C = x . y
A PARALLEL BINARY ADDER
• Parallel binary adders are used to add two binary
numbers.
• Example:
• If we want to add two four-bit numbers, we need to construct a parallel four-bit binary adder.
ADDING BIGGER BINARY NUMBERS
EXAMPLE
• Add two numbers say, 9 and 11.
• The Binary equivalent of decimal 9 is 1001. and that of decimal 11 is 1011.
• The final output of the system is 10100.
HA FA FA FA
1 1
1 1
0 0
0 1
0 0 1 0
1 1 0
carry carry carry
sum sum sum sum
carry
ADDING BIGGER BINARY NUMBERS
• A half adder has 4 logic gates.
• A full adder has two half adders plus a OR gate
– Total of 9 logic gates
• To add n bit binary numbers, you need 1 HA and n-1 FAs
• To add 32 bit binary numbers, you need 1 HA and 31 FAs
– Total of 4+9*31 = 283 logic gates
• To add 64 bit binary numbers, you need 1 HA and 63 FAs
MORE ABOUT LOGIC GATES
• To implement a logic gate in hardware, you use a transistor.
• Transistors are all enclosed in an “IC”, or
integrated circuit.
FLIP-FLOPS
• Consider the following circuit:
MEMORY
• A flip-flop holds a single bit of memory– The bit “flip-flops” between the two NAND gates.
• In reality, flip-flops are a bit more complicated – Have 5 (or so) logic gates (transistors) per
flip-flop.
• Consider a 1 Gb memory chip.
– 1 Gb = 8,589,934,592 bits of memory. – That’s about 43 million transistors!