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

date post

28-Dec-2015Category

## Documents

view

213download

0

Embed Size (px)

### Transcript of CPSC 171 Introduction to Computer Science Boolean Logic, Gates, & Circuits.

CPSC 171 Introduction to Computer ScienceBoolean Logic, Gates, & Circuits

AnnouncementsRead Chapter 4

Exam, Oct 2nd in class

Boolean LogicA 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 ' ~)

Boolean Operatorsa AND btrue only when A and B are both truea OR btrue when A is true, B is true, or both are trueNOT atrue when A is false

Truth TablesTruth tables can be used to capture when an expression is true, given its inputsYou make truth tables for AND and NOT

Example Boolean Expressions(a AND b) OR (NOT a AND c)ab + ~acab+c

Truth tables can be made for complex expressions as well

Boolean Logic (continued)Example: (a AND b) OR ((NOT b) and (NOT a))

abValue001010100111

GatesGatesHardware devices built from transistors to mimic Boolean logicAn 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 lineOutputs a 1 when both inputs are 1

Gates (continued)OR gate (page 163 in text)Two input lines, one output lineOutputs a 1 when either input is 1

NOT gate (page 161 in textOne input line, one output lineOutputs a 1 when input is 0 and vice versa

Figure 4.15The Three Basic Gates and Their Symbols

CircuitsA 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

Example CircuitIf a, b, c, and d are all true the output can be determined by tracing through the circuitoutput11111100

Designing CircuitsA circuit construction algorithmTruth Table ConstructionDetermine outputs for every possible inputSub-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 inputSub-expression combination (using OR gates)Take each subexpression and combine them, 2 at a time, using OR gatesCircuit Diagram ProductionConstruct final circuit by converting Boolean operators into gates

Example Circuit DesignDesign 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

Examples of Circuit Design and ConstructionCompare-for-equality circuitAddition circuitBoth circuits can be built using the circuit design algorithm

A Compare-for-Equality CircuitCE compares two unsigned binary integers for equalityBuilt 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 (continued)

1-CE circuit truth table

A Compare-for-Equality Circuit (continued)1-CE Boolean expressionFirst case: (NOT a) AND (NOT b)Second case: a AND bCombined:((NOT a) AND (NOT b)) OR (a AND b)

Figure 4.22One-Bit Compare-for-Equality Circuit

N-Bit Compare for Equality Circuit

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

An Addition CircuitAdds two unsigned binary integers, setting output bits and an overflowBuilt from 1-bit adders (1-ADD)Starting with rightmost bits, each pair producesA value for that orderA carry bit for next place to the left

An Addition Circuit (continued)1-ADD truth tableInputOne bit from each input integerOne carry bit (always zero for rightmost bit)OutputOne bit for output place valueOne carry bit

Figure 4.24The 1-ADD Circuit and Truth Table

An Addition Circuit (continued)Building the full adder

Put rightmost bits into 1-ADD, with zero for the input carrySend 1-ADDs output value to output, and put its carry value as input to 1-ADD for next bits to leftRepeat process for all bitsSee pg 174, 175, 176