Lecture 3: Truth Tables and Logic Gates. Instructor: Joelle Pineau Class web page:

Similar documents
Lecture #21 March 31, 2004 Introduction to Gates and Circuits

ECE199JL: Introduction to Computer Engineering Fall 2012 Notes Set 2.4. Example: Bit-Sliced Comparison

Learning Objectives: Topic Karnaugh Maps. At the end of this topic you will be able to;

Section 001. Read this before starting! You may use one sheet of scrap paper that you will turn in with your test.

Homework. Update on website issue Reading: Chapter 7 Homework: All exercises at end of Chapter 7 Due 9/26

COMP 102: Computers and Computing

The Plurality-with-Elimination Method

COMP combinational logic 1 Jan. 18, 2016

Logic Gates and Boolean Algebra ENT263

(Refer Slide Time 3:31)

Introduction to Computer Architecture

Binary Values. CSE 410 Lecture 02

Starting Boolean Algebra

GC03 Boolean Algebra

At this point in our study of digital circuits, we have two methods for representing combinational logic: schematics and truth tables.

Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18

Henry Lin, Department of Electrical and Computer Engineering, California State University, Bakersfield Lecture 7 (Digital Logic) July 24 th, 2012

Read this before starting!

Digital Circuits ECS 371

Data Structure and Algorithm Homework #3 Due: 1:20pm, Thursday, May 16, 2017 TA === Homework submission instructions ===

Lecture 6: Signed Numbers & Arithmetic Circuits. BCD (Binary Coded Decimal) Points Addressed in this Lecture

2. BOOLEAN ALGEBRA 2.1 INTRODUCTION

Voting Methods and Colluding Voters

Logic Design (Part 2) Combinational Logic Circuits (Chapter 3)

The Pairwise-Comparison Method

Grade 7/8 Math Circles Fall November 6/7/8 Boolean Logic

QED Q: Why is it called the triangle inequality? A: Analogue with euclidean distance in the plane: picture Defn: Minimum Distance of a code C:

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

Three Types of Probability

Chapter 3. Set Theory. 3.1 What is a Set?

Memory Hierarchies. Instructor: Dmitri A. Gusev. Fall Lecture 10, October 8, CS 502: Computers and Communications Technology

2.1 Binary Logic and Gates

CS/COE 0447 Example Problems for Exam 2 Spring 2011

Functional Block: Decoders

12-4 Geometric Sequences and Series. Lesson 12 3 quiz Battle of the CST s Lesson Presentation

6.S189 Homework 1. What to turn in. Exercise 1.1 Installing Python. Exercise 1.2 Hello, world!

Binary. Hexadecimal BINARY CODED DECIMAL

Extra Practice Problems 2

ROCK PAPER SCISSORS Rock Paper Scissors Lab Project Using C or C++

CS40-S13: Functional Completeness

Experiment 4 Boolean Functions Implementation


1. Prove that if you have tri-state buffers and inverters, you can build any combinational logic circuit. [4]

6.149 Checkoff 2. What to complete. Recall: Creating a file and running a program in IDLE.

Chapter 2: Universal Building Blocks. CS105: Great Insights in Computer Science

Grade 7/8 Math Circles Fall November 6/7/8 Boolean Logic

Order from Chaos. Nebraska Wesleyan University Mathematics Circle

(Refer Slide Time 6:48)

What s a Tri-state Buffer?

Midterm #1a Fall minutes

MULTIPLE OPERAND ADDITION. Multioperand Addition

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

CSE 20 DISCRETE MATH WINTER


Possibilities of Voting

Announcements. HW0 is posted on schedule, due next Friday at 9pm (pretty easy)

Date Performed: Marks Obtained: /10. Group Members (ID):. Experiment # 09 MULTIPLEXERS

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

CS 31: Introduction to Computer Systems. 03: Binary Arithmetic January 29

Quick Review of Graphs

MODULE 5 - COMBINATIONAL LOGIC

2/8/2017. SOP Form Gives Good Performance. ECE 120: Introduction to Computing. K-Maps Can Identify Single-Gate Functions

How to Win Coding Competitions: Secrets of Champions. Week 3: Sorting and Search Algorithms Lecture 7: Lower bound. Stable sorting.

CS140 Lecture 03: The Machinery of Computation: Combinational Logic

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

Chap-2 Boolean Algebra

Order from Chaos. University of Nebraska-Lincoln Discrete Mathematics Seminar

Digital Fundamentals

Von Neumann Architecture

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

Topics of this Slideset. CS429: Computer Organization and Architecture. Digital Signals. Truth Tables. Logic Design

Lecture Notes 15 Number systems and logic CSS Data Structures and Object-Oriented Programming Professor Clark F. Olson

EECS 270 Midterm Exam

Lecture 7 Logic Simplification

Here is a sample IDLE window illustrating the use of these two functions:

LAB #1 BASIC DIGITAL CIRCUIT

Boolean Algebra & Digital Logic

EE292: Fundamentals of ECE

Chapter 2: Combinational Systems

COMP-202: Foundations of Programming. Lecture 6: Conditionals Jackie Cheung, Winter 2016

Logic and Computer Design Fundamentals. Chapter 2 Combinational Logic Circuits. Part 3 Additional Gates and Circuits

Exercises Computational Complexity

Kinds Of Data CHAPTER 3 DATA REPRESENTATION. Numbers Are Different! Positional Number Systems. Text. Numbers. Other

MIDTERM EXAMINATION Networked Life (NETS 112) November 21, 2013 Prof. Michael Kearns

Chapter Three. Digital Components

Condition Controlled Loops. Introduction to Programming - Python

Feature Extractors. CS 188: Artificial Intelligence Fall Some (Vague) Biology. The Binary Perceptron. Binary Decision Rule.

MATH 1340 Mathematics & Politics

I may not have gone where I intended to go, but I think I have ended up where I needed to be. Douglas Adams

Section 4.3: Derivatives and the Shapes of Curves

Chapter 2. Boolean Expressions:

CSE303 Logic Design II Laboratory 01

Read this before starting!

Contents. Chapter 3 Combinational Circuits Page 1 of 34

Introduction to Boolean Algebra

MAT137 Calculus! Lecture 31

A B A+B

The Game of Criss-Cross

George Hartas, MS. Educational Assistant for Mathematics Remediation. MAT 025 Instructor. Table of Contents

CprE 281: Digital Logic

Transcription:

COMP 102: Computers and Computing Lecture 3: Truth Tables and Logic Gates Instructor: (jpineau@cs.mcgill.ca) Class web page: www.cs.mcgill.ca/~jpineau/comp102 Practice example You are given the responsibility of building an automatic voting machine. ssume there are 2 candidates. ssume there are 3 voters, everyone gets a single vote. The candidate with the most votes wins. What logical variables would you use? Can you write a logical expression, which evaluates who wins (True = Candidate, False = Candidate )? 2 1

Practice example Input logical variables: V1 = Vote of person 1 (True=Candidate, False=Candidate ) V2 = Vote of person 2 (True=Candidate, False=Candidate ) V3 = Vote of person 3 (True=Candidate, False=Candidate ) logical variables WINNER = {True=Candidate wins, False=Candidate wins} Logical expression: WINNER = (V1 ND V2) (V1 ND V3) (V2 ND V3) How would you check if the logical expression is correct? 3 Checking logical expressions Computer must be ready for any input, and must compute correct results in all cases. Must go through all possible input combinations: V1=True, V2=True, V3=True WINNER =? V1=True, V2=True, V3=False WINNER =? V1=True, V2=False, V3=True WINNER =? V1=True, V2=False, V3=False WINNER =? V1=False, V2=True, V3=True WINNER =? V1=False, V2=True, V3=False WINNER =? V1=False, V2=False, V3=True WINNER =? V1=False, V2=False, V3=False WINNER =? 4 2

Truth table Write-up a table with all possible input combinations, and check the output the output for each row. Inputs: s: V1 V2 V3 WINNER 0 0 0 0 (= Candidate ) 0 0 1 0 (= Candidate ) 0 1 0 0 (= Candidate ) 0 1 1 1 (= Candidate ) 1 0 0 0 (= Candidate ) 1 0 1 1 (= Candidate ) 1 1 0 1 (= Candidate ) 1 1 1 1 (= Candidate ) This is called a Truth Table. 5 Comparing logical expressions Recall our previous expression: WINNER= (V1 ND V2) (V1 ND V3) (V2 ND V3) You can also extract the logical expression directly from the Truth Table: WINNER = ( (NOT V1) ND V2 ND V3) (V1 ND (NOT V2) ND V3) (V1 ND V2 ND (NOT V3)) (V1 ND V2 ND V3) 6 3

Extracting logical expression from the truth table Recall: WINNER = ( (NOT V1) ND V2 ND V3) (V1 ND (NOT V2) ND V3) (V1 ND V2 ND (NOT V3)) (V1 ND V2 ND V3) How do we get this logical expression: Consider each line in the table. If the line has OUTPUT=1, this line must be included in the logical expression as a sub-expression. The sub-expression includes all variables, where true variables are included without modification and negative variables are preceded by NOT operator. The variables in a sub-expression are separated by ND logical operators. Sub-expressions are separated by logical operators. 7 Pros / cons of the two logical expressions Compare: E1: WINNER = (V1 ND V2) (V1 ND V3) (V2 ND V3) E2: WINNER = ( (NOT V1) ND V2 ND V3) (V1 ND (NOT V2) ND V3) (V1 ND V2 ND (NOT V3)) (V1 ND V2 ND V3) E1 is more compact. E2 we can get directly from the truth table. 8 4

How do we implement a logical expression? ssume we have logic gates (or blocks) that implement each logical operator. Input Logic gate Input Input Logic gate Single input Double input Logic gates are the building blocks of digital electronics and are used to build telecommunication devices, computers, etc. 9 Logic gates and their truth table: ND Truth table for the ND operator: Input : Input : : 0 0 0 0 1 0 1 0 0 1 1 1 The ND gate is usually drawn as a half-moon. It is a double input gate. Input ND Input 10 5

Logic gates and their truth table: Truth table for the operator: Input : Input : : 0 0 0 0 1 1 1 0 1 1 1 1 The gate is usually drawn as a crescent-shape. It is a double input gate. Input Input 11 Logic gates and their truth table: NOT Truth table for the NOT operator: Input: : 0 1 1 0 The NOT gate is usually drawn as a triangle, with a small circle. The circle is there to indicate the output inverts the input. It is a single input gate. Input NOT 12 6

Can we implement E1 and E2? Problem: E1 needs a 3-input gate. E2 needs a 3-input ND gate. Solution: Make it by grouping gates C = C nd similarly for ND gates. 13 More complicated gates: NND NND = Not ND This corresponds to an ND gate followed by a NOT gate. = NOT ( ND ) 14 7

More complicated gates: N N = Not This corresponds to an gate followed by a NOT gate. = NOT ( ) 15 More complicated gates: EX- EX- = EXclusive This corresponds to an gate, but the output is negative if both inputs are true. 16 8

Combining logic gates Logic gates can be combined to produce complex logical expressions. E.g.: WINNER = (V1 ND V2) (V1 ND V3) (V2 ND V3) V1 V2 ND ND V3 ND Logic gates can also be combined to substitute for another type of gate. 17 Example NOT NOT NOT ND Is there a unique set of blocks to represent a given expression? No! (Hint: Just write out the truth table for each set of gates, and see whether they are the same.) 18 9

De Morgan s Theorem Logical gates Logical expression NOT NOT ( ) NOT NOT ND (NOT ) ND (NOT ) Theorem: If neither nor is true, then both and must be false. 19 How do we choose which expression to implement? Sometimes function can be more compact (recall E1 vs E2). Multiple logic gates (of one type) are placed on a single chip; it may be more efficient to use all of them, rather than require another chip (of a different type). 4001 Chip: four 2-input N gates 20 10

Leveraging this insight ny logical gate can be replaced by a set of NND gates. This means all we ever need, to implement any logical expression, is a lot of NND gates! Total number of gates may be larger, but total number of chips is usually smaller. (Note: Same thing can be done with N gates.) 21 harder problem Imagine you play a game of Rock-Paper-Scissors against your friend. ssume you want a computer to automatically decide if you win or not. What logical variables would you use? Can you write a logical expression, which evaluates whether or not you win (True = win, False = loose)? E.g. If you play Rock and your friend players Scissor, it returns True, and similarly for other possible plays. 22 11

Rock-Paper-Scissors: Logical variables Input: choice of player 1, choice of player 2 : outcome of the game (according to the rules) Need to convert input and output to binary representation. Need 2 variables to represent the possible choice of each player 01 = Scissors 10 = Paper 11 = Rock So we need 4 variables to represent the choice of both players. Need 2 variables to represent the possible outcomes. 10 = Player 1 wins 01 = Player 2 wins 00 = Tie 23 Rock-Paper-Scissors: Other representations There are other possible binary representations. Some are equivalent: same expressive power, same number of bits E.g. Scissors = 00, Paper = 01, Rock = 11 Some are not equivalent: E.g. Scissors = 0, Paper = 1, Rock = 1 (Fewer bits, less expressive power) E.g. Scissors = 000, Paper = 001, Rock = 011 (Same power, but more bits) 24 12

Rock-Paper-Scissors: Truth Table Input logical variables: variables: Player1: Player2: C D E F Scissors 0 1 Scissors 0 1 Tie 0 0 Scissors 0 1 Paper 1 0 Player 1 wins 1 0 Scissors 0 1 Rock 1 1 Player 2 wins 0 1 Paper 1 0 Scissors 0 1 Player 2 wins 0 1 Paper 1 0 Paper 1 0 Tie 0 0 Paper 1 0 Rock 1 1 Player 1 wins 1 0 Rock 1 1 Scissors 0 1 Player 1 wins 1 0 Rock 1 1 Paper 1 0 Player 2 wins 0 1 Rock 1 1 Rock 1 1 Tie 0 0 What happens to the unspecified input (e.g. 0000)? Doesn t matter what the output is! 25 Rock-Paper-Scissors: Logical expressions Need two expressions, one for each of the output bits. E = ( (NOT ) ND ND C ND (NOT D) ) ( ( ND (NOT ) ND C ND D) ) ( ( ND ND (NOT C) ND D) ) F = ( (NOT ) ND ND C ND D) ( ND (NOT ) ND (NOT C) ND D) ( ND ND C ND (NOT D) ) 26 13

Rock-Paper-Scissors: Logical gates Final step! Try this at home. 27 Take-home message Know how to build a truth table from a logical problem description. Know how to extract the logical expressions from the truth table. Learn to identify and use the basic gates: ND,, NOT. Understand the link between truth tables and logic gates. Know how to use combinations of gates to implement logical expressions. Understand that many different sets of gates can represent a given logical expression. e able to state and understand De Morgan s theorem. Homework 2 posted. Due next Thursday. 28 14