CPSC 171 Introduction to Computer Science

24
CPSC 171 Introduction to Computer Science Boolean Logic, Gates, & Circuits

description

CPSC 171 Introduction to Computer Science. Boolean Logic, Gates, & Circuits. Announcements. Read Chapter 4 Exam, Oct 2 nd in class. Boolean Logic. A Boolean variable , A, is either true or false A Boolean expression , (A AND B), evaluates to either true or false - PowerPoint PPT Presentation

Transcript of CPSC 171 Introduction to Computer Science

Page 1: CPSC 171 Introduction to Computer Science

CPSC 171 Introduction to Computer Science

Boolean Logic, Gates, & Circuits

Page 2: CPSC 171 Introduction to Computer Science

Announcements

Read Chapter 4

Exam, Oct 2nd in class

Page 3: CPSC 171 Introduction to Computer Science

Boolean Logic

A Boolean variable, A, is either true or falseA Boolean expression, (A AND B), evaluates to either true or falseBoolean operators include: AND (& • ) OR ( + ) NOT (a bar ' ¬ ~)

Page 4: CPSC 171 Introduction to Computer Science

Boolean Operators

a AND btrue only when A and B are both true

a OR btrue when A is true, B is true, or both are

true

NOT atrue when A is false

Page 5: CPSC 171 Introduction to Computer Science

Truth Tables

Truth tables can be used to capture when an expression is true, given its inputs

a b a AND b

0 0 1

0 1 1

1 0 1

1 1 1

You make truth tables for AND and NOT

Page 6: CPSC 171 Introduction to Computer Science

Example Boolean Expressions

(a AND b) OR (NOT a AND c)a·b + ~a·cab+āc

Truth tables can be made for complex expressions as well

Page 7: CPSC 171 Introduction to Computer Science

a b Value

0 0 1

0 1 0

1 0 0

1 1 1

Example: (a AND b) OR ((NOT b) and (NOT a))

Boolean Logic (continued)

Page 8: CPSC 171 Introduction to Computer Science

Gates

Gates Hardware devices built from transistors

to mimic Boolean logic An electronic device that operates on a

collection of binary inputs to produce a single binary output

AND gate (page 161 in text) Two input lines, one output line Outputs a 1 when both inputs are 1

Page 9: CPSC 171 Introduction to Computer Science

Gates (continued)

OR gate (page 163 in text) Two input lines, one output line Outputs a 1 when either input is 1

NOT gate (page 161 in text One input line, one output line Outputs a 1 when input is 0 and vice

versa

Page 10: CPSC 171 Introduction to Computer Science

Figure 4.15The Three Basic Gates and Their Symbols

Page 11: CPSC 171 Introduction to Computer Science

Circuits

A collection of logic gates that transforms a set of binary inputs into a set of binary outputsWire gates together keeping constraints for the number of inputs to any gate

Page 12: CPSC 171 Introduction to Computer Science

Example Circuit

If a, b, c, and d are all true the output can be determined by tracing through the circuit

a b

c d

output

1

1

1

1

1

1

0

0

Page 13: CPSC 171 Introduction to Computer Science

Designing CircuitsA circuit construction algorithm

1. Truth Table ConstructionDetermine outputs for every possible input

2. Sub-expression Construction (using AND and NOT gates)For each output find the rows that are 1 and build a

sub-expression that is true for the exact input

3. Sub-expression combination (using OR gates)Take each subexpression and combine them, 2 at a

time, using OR gates

4. Circuit Diagram ProductionConstruct final circuit by converting Boolean operators

into gates

Page 14: CPSC 171 Introduction to Computer Science

Example Circuit Design

Design a 3-input circuit that is true if exactly two inputs are true, and false otherwise

You Try it: Design a 2-input circuit that is true if the inputs are the same, and false otherwise

Page 15: CPSC 171 Introduction to Computer Science

Examples of Circuit Design and Construction

Compare-for-equality circuit

Addition circuit

Both circuits can be built using the circuit design algorithm

Page 16: CPSC 171 Introduction to Computer Science

CE compares two unsigned binary integers for equality

Built by combining together 1-bit comparison circuits (1-CE)

Integers are equal if corresponding bits are equal (AND together 1-CD circuits for each pair of bits)

A Compare-for-Equality Circuit

Page 17: CPSC 171 Introduction to Computer Science

1-CE circuit truth table

a b Output

0 0 1

0 1 0

1 0 0

1 1 1

A Compare-for-Equality Circuit (continued)

Page 18: CPSC 171 Introduction to Computer Science

1-CE Boolean expression

First case: (NOT a) AND (NOT b)

Second case: a AND b

Combined:

((NOT a) AND (NOT b)) OR (a AND b)

A Compare-for-Equality Circuit (continued)

Page 19: CPSC 171 Introduction to Computer Science

Figure 4.22One-Bit Compare-for-Equality Circuit

Page 20: CPSC 171 Introduction to Computer Science

N-Bit Compare for Equality Circuit

AND together the 1-CE circuits, two at a time

Page 21: CPSC 171 Introduction to Computer Science

An Addition CircuitAdds two unsigned binary integers, setting output bits and an overflow

Built from 1-bit adders (1-ADD)

Starting with rightmost bits, each pair produces

A value for that order

A carry bit for next place to the left

Page 22: CPSC 171 Introduction to Computer Science

1-ADD truth table

Input

One bit from each input integer

One carry bit (always zero for rightmost bit)

Output

One bit for output place value

One carry bit

An Addition Circuit (continued)

Page 23: CPSC 171 Introduction to Computer Science

Figure 4.24The 1-ADD Circuit and Truth Table

Page 24: CPSC 171 Introduction to Computer Science

Building the full adder

Put rightmost bits into 1-ADD, with zero for the input carry

Send 1-ADD’s output value to output, and put its carry value as input to 1-ADD for next bits to left

Repeat process for all bits See pg 174, 175, 176

An Addition Circuit (continued)