61
© Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement) Signed Arithmetic

Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Lecture 3 Slides

Logic Functions

Signed Systems

(Signed Magnitude, 2’s Complement)

Signed Arithmetic

Page 2: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

SIGNED SYSTEMS

Page 3: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Binary Representation Systems

• Integer Systems

– Unsigned

• Unsigned (Normal) binary

– Signed

• Signed Magnitude

• 2’s complement

• 1’s complement*

• Excess-N*

• Floating Point

– For very large and small

(fractional) numbers

• Codes

– Text

• ASCII / Unicode

– Decimal Codes

• Weighted Codes

– BCD (Binary Coded

Decimal) / (8421 Code)

– 2421 Code*

– 84-2-1 Code

• Non-weighted Codes

– Excess-3

* = Not covered in this class

Page 4: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Interpreting Binary Strings

• Given a string of 1’s and 0’s, you need to know

the representation system being used, before you

can understand the value of those 1’s and 0’s.

• Information (value) = Bits + Context (System)

01000001 = ?

6510 ‘A’ASCII

41BCD

Unsigned

Binary system ASCII

systemBCD System

Page 5: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Unsigned and Signed

• Normal (unsigned) binary can only

represent positive numbers

– All place values are positive

• To represent negative numbers we must

use a modified binary representation that

takes into account sign (pos. or neg.)

– We call these signed representations

Page 6: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Signed Number Representation

• 2 Primary Systems

– Signed Magnitude

– Two’s Complement (most widely used for integer

representation)

Page 7: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Signed numbers

• All systems used to represent

negative numbers split the

possible binary combinations in

half (half for positive numbers /

half for negative numbers)

• In both signed magnitude and

2’s complement, positive and

negative numbers are

separated using the MSB

– MSB=1 means negative

– MSB=0 means positive

00000001

0010

0011

0100

0101

0110

0111

1000

1111

1110

1101

1100

1011

1010

1001

+-

Page 8: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Signed Magnitude System

• MSB no longer used as a place value, now represents the sign (1 if negative, 0 if positive)

1248

4-bit

Unsigned

4-bit Signed

Magnitude

0 to 15

Bit

0

Bit

1

Bit

2

Bit

3

124+/-

-7 to +7

Bit

0

Bit

1

Bit

2

Bit

3

8-bit Signed

Magnitude163264+/-

-127 to +127

Bit

4

Bit

5

Bit

6

Bit

7

1248

Bit

0

Bit

1

Bit

2

Bit

3

Page 9: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Signed Magnitude Examples

4-bit Signed

Magnitude

124+/-

= -5

8-bit Signed

Magnitude

124+/-

= +3

163264+/- 1248

Notice that +3 in signed

magnitude is the same

as in the unsigned

system

124+/-

= -7

= -1

163264+/- 1248

= +25

Important: Positive numbers have the same representation in signed

magnitude as in normal unsigned binary

Page 10: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Signed Magnitude Examples

4-bit Signed

Magnitude

124+/-

= -5

8-bit Signed

Magnitude

1011

124+/-

= +31100

163264+/- 1248

Notice that +3 in signed

magnitude is the same

as in the unsigned

system

124+/-

= -71111

0001 1000 = -1

163264+/- 1248

1000 1001 = +25

Important: Positive numbers have the same representation in signed

magnitude as in normal unsigned binary

Page 11: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Disadvantages of Signed Magnitude

• Wastes a combination representing -0

• Performing addition/subtraction requires a

more complex algorithm

Page 12: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

2’s Complement System

• Normal binary place values except MSB has negative weight

• MSB of 1 = -2n-1

1248

4-bit

Unsigned

4-bit

2’s complement

0 to 15

Bit

0

Bit

1

Bit

2

Bit

3

124-8

-8 to +7

Bit

0

Bit

1

Bit

2

Bit

3

8-bit

2’s complement163264-128

-128 to +127

Bit

4

Bit

5

Bit

6

Bit

7

1248

Bit

0

Bit

1

Bit

2

Bit

3

Page 13: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

2’s Complement Examples

4-bit

2’s complement

124-8

= -5

8-bit

2’s complement

124-8

= +3

163264-128 1248

Notice that +3 in 2’s

comp. is the same as

in the unsigned system

124-8

= -1

= -127

163264-128 1248

= +25

Important: Positive numbers have the same representation in 2’s complement

as in normal unsigned binary

Page 14: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

2’s Complement Examples

4-bit

2’s complement

124-8

= -5

8-bit

2’s complement

1101

124-8

= +31100

163264-128 1248

Notice that +3 in 2’s

comp. is the same as

in the unsigned system

124-8

= -11111

0001 1000 = -127

163264-128 1248

1000 1001 = +25

Important: Positive numbers have the same representation in 2’s complement

as in normal unsigned binary

Page 15: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

2’s Complement Notes

• Range with n-bits of 2’s complement

system

– [-2n-1 to +2n-1-1]

• Largest magnitude negative number:

– -2n-1: 1000…0000

• Largest magnitude positive number:

– +2n-1-1: 0111…1111

• -110:

– 1111…1111

Page 16: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Taking the Negative

• Given a number in signed magnitude or 2’s

complement how do we find its negative

– Signed Magnitude (Easy)

• Flip the sign bit

• 0001 = +110 => 1001 = -110

– 2’s complement

• Taking the negative is equivalent to an operation we term,

“Taking the 2’s complement”

• “Take the 2’s complement” is defined as:

– Flip all bits of the number (this is called the 1’s complement of a

number)

– Add 1 to the result of the bit flip

– Drop any carry-out of the MSB column

Page 17: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Taking the 2’s Complement

• Invert (flip) each bit

(take the 1’s

complement)

– 1’s become 0’s

– 0’s become 1’s

• Add 1 (drop final carry-

out, if any)

010011

101100Bit flip is called the 1’s

complement of a number

+ 1

101101

Original number = +19-32 16 8 4 2 1

Resulting number = -19

Important: Taking the 2’s complement is equivalent to

taking the negative (negating)

Page 18: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Taking the Complement

• Given +2210 = 010110,

find -2210 in 2’s

complement system

• 010 = 0000, what happens

when we take the 2’s

complement?

• -810 = 1000, what happens

when we take the 2’s

complement?

Page 19: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

2’s Complement Tricks

• Normal method of taking the 2’s complement:– Flip bits and add 1

• Trick– Start from LSB and work your way left towards MSB

– Copy bits through the first ‘1’ you encounter

– Flip every bit after that

011010 Start from the LSB

Copy bits through the

first ‘1’

Flip (invert) every

bit after that

100110

011010

100101+ 1100110

Normal 2’s complement method 2’s Complement Trick

Page 20: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

2’s Complement System Facts

• Uses binary place values but with MSB having

negative weight

• Special Numbers

– 0 = All 0’s (00…00)

– -1 = All 1’s (11…11)

– Max Positive = 0 followed by all 1’s (011..11)

– Max Negative = 1 followed by all 0’s (100…00)

• 2’s complement numbers are negated by taking

the 2’s complement of the number

Page 21: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Zero and Sign Extension

• Zero extension (unsigned) and Sign extension (2’s comp.) is the process of increasing the number of bits used to represent a value without changing the value itself

2’s complement = Sign Extension (Replicate sign bit):

Unsigned = Zero Extension (Always add leading 0’s):

111011 = 00111011

011010 = 00011010

110011 = 11110011

pos.

neg.

Increase a 6-bit number to 8-bit

number by zero extending

Sign bit is just repeated as

many times as necessary

Page 22: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Zero and Sign Truncation

• Zero truncation (unsigned) and Sign truncation (2’s comp.) is the process of decreasing the number of bits used to represent a value without changing the value itself

2’s complement = Sign Truncation (Remove copies of sign bit):

Unsigned = Zero Truncation (Remove leading 0’s):

00111011 = 111011

00011010 = 011010

11110011 = 10011

pos.

neg.

Decrease an 8-bit number to 6-bit

number by truncating 0’s. Can’t

remove a ‘1’ because value is changed

Any copies of the MSB can be

removed without changing the

numbers value. Be careful not to

change the sign by cutting off

ALL the sign bits.

Page 23: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Summary

• Signed Magnitude

– Range (-2n-1 – 1 to +2n-1 – 1)

• 2’s Complement

– Range (-2n-1 to +2n-1 – 1)

Page 24: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

SIGNED ARITHMETIC

2’s complement addition and subtraction

Page 25: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

2’s Complement Addition/Subtraction

• Addition– No special steps need be taken, add column by

column

– Sign of the numbers do not matter

– Drop any final carry-out

• Subtraction– Any subtraction can be converted to addition based on

the fact that A-B = A+(-B)

– Rather than subtract B, add -B

– Find -B by taking the 2’s complement of B

– (A-B) becomes (A + 1’s comp. of B + 1)

– Drop any carry-out

Page 26: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

2’s Complement Addition

• No matter the sign of the operands just add as normal

• Drop any extra carry out

0011

+ 0010

(3)

(2)

1101

+ 0010

(-3)

(2)

0011

+ 1110

(3)

(-2)

1101

+ 1110

(-3)

(-2)

Page 27: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

2’s Complement Addition

• No matter the sign of the operands just add as normal

• Drop any extra carry out

0011

+ 0010

0101

(3)

(2)

(5)

1101

+ 0010

1111

(-3)

(2)

(-1)

0011

+ 1110

0001

(3)

(-2)

(1)

1101

+ 1110

1011

(-3)

(-2)

(-5)

0000 0000

1110 Drop final

carry-out 1100

Page 28: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

2’s Complement Subtraction

• Take the 2’s complement of the subtrahend and add to the original minuend

• Drop any extra carry out

0100

- 0110

(+4)

(+6)

1101

- 1000

(-3)

(-8)

Page 29: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

2’s Complement Subtraction

• Take the 2’s complement of the subtrahend and add to the original minuend

• Drop any extra carry out

0100

- 0110

(+4)

(+6)

0001_

0100

1001

+ 0001

1110

1’s comp. of +2

Add 1

1101

- 1000

(-3)

(-8)

1111_

1101

0111

+ 0001

0101

1’s comp. of -8

Add 1

Drop final

carry-out

Page 30: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

2’s Complement Subtraction

• Take the 2’s complement of the subtrahend and add to the original minuend

• Drop any extra carry out

0100

- 0110

(+4)

(+6)

0001_

0100

1001

+ 0001

1110

1’s comp. of +2

Add 1

1101

- 1000

(-3)

(-8)

1111_

1101

0111

+ 0001

0101

1’s comp. of -8

Add 1

Drop final

carry-out

Page 31: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

DIGITAL LOGIC

Basic Gates

Page 32: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Digital Logic

• Digital Logic is built on…

– Binary variables can be only one of two

possible values (e.g. 0 or 1)

– Three operations on binary variables

• AND (all inputs true => output is true)

• OR (any inputs true => output is true)

• NOT (output is opposite of input)

Page 33: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Transistors

• The building blocks of logic gates (AND, OR, NOT)

• Electronic switches

– 2 positions (on/off, conducting/non-conducting)

– Output voltage of a transistor = high or low

on

offControlling

Input

(Gate )

Output

(Drain )

Source

The voltage here

determines if current

can flow between

drain and source

A ‘1’ here closes

the switch

Schematic Symbol of a

Transistor

Functional View of a

Transistor as a Switch

Page 34: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Transistors and Logic

• The connection of transistors determines the

logical operation…

– In series (i.e. one after the next) = AND

• All transistors must be on to light up the light

– In parallel = OR

• Any transistor must be on to light up the light

A B

Voltage

Source

L

L = A and B

A

BVoltage

Source

L

L = A or B

Transistors in

SERIES = AND

Transistors in

PARALLEL = OR

Page 35: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

AND, OR, NOT Gates

NOT (Inverter) AND OR

X ZX

YZ Z

X

Y

X Y Z

0 0 0

0 1 0

1 0 0

1 1 1

X Y Z

0 0 0

0 1 1

1 0 1

1 1 1

X Z

0 1

1 0

YXZ YXZ ~XXXZ or or '

AND = ‘ALL’

(true when ALL

inputs are true)

OR = ‘ANY’

(true when ANY

input is true)

Page 36: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Gates

• Gates can have more than 2 inputs but the functions stay the same– AND = output = 1 if ALL inputs are 1

• Outputs 1 for only 1 input combination

– OR = output = 1 if ANY input is 1

• Outputs 0 for only 1 input combination

X Y Z F

0 0 0 0

0 0 1 0

0 1 0 0

0 1 1 0

1 0 0 0

1 0 1 0

1 1 0 0

1 1 1 1

X Y Z F

0 0 0 0

0 0 1 1

0 1 0 1

0 1 1 1

1 0 0 1

1 0 1 1

1 1 0 1

1 1 1 1

3-input AND 3-input OR

Fx

y

z

Fx

y

z

Page 37: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

NAND and NOR Gates

NAND NOR

ZX

YZ

X Y Z

0 0 1

0 1 0

1 0 0

1 1 0

X

Y

X Y Z

0 0 1

0 1 1

1 0 1

1 1 0

YXZ YXZ

X Y Z

0 0 0

0 1 0

1 0 0

1 1 1

X Y Z

0 0 0

0 1 1

1 0 1

1 1 1

AND NAND OR NOR

True if NOT ANY

input is true

True if NOT ALL

inputs are true

Page 38: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

XOR and XNOR Gates

XOR

ZX

Y

X Y Z

0 0 0

0 1 1

1 0 1

1 1 0

XNOR

ZX

Y

X Y Z

0 0 1

0 1 0

1 0 0

1 1 1

YXZ YXZ

True if an odd # of inputs are true

2 input case: True if inputs are different

True if an even # of inputs are true

2 input case: True if inputs are same

Page 39: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

LOGIC FUNCTIONS INTRO

Page 40: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Arithmetic vs. Logic Functions

Arithmetic => f(x1,x2,…,xn)

• Domain => ?

• Range => ?

(i.e. maps ____ to ____)

• Representations…

Logic => f(x1,x2,…,xn)

• Domain => ?

• Range => ?

• Representations

Page 41: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Arithmetic vs. Logic Functions

Arithmetic => f(x1,x2,…,xn)

• Domain => {Real}n

• Range => Real

Logic => f(x1,x2,…,xn)

• Domain => {0, 1}n

– Vector of n zeros or ones

– 2n such vectors are

possible

• Range => {0, 1}

Page 42: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Logic Function Domain

x

y

z

0 1

0 1

0 1

X Y Z

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1

z

yx

Truth Table

Binary Decision Tree

Venn Diagram

if(x,y,z == 000) then

else if (x,y,z == 001) then

else if (x,y,z == 010) then

If or Case statement

Page 43: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

3-bit Prime Number Function

x

y

z

0 1

0 1

0 1

X Y Z P

0 0 0 0

0 0 1 0

0 1 0 1

0 1 1 1

1 0 0 0

1 0 1 1

1 1 0 0

1 1 1 1

X Y Z P

0 0 0 0

0 0 1 0

0 1 0 1

0 1 1 1

1 0 0 0

1 0 1 1

1 1 0 0

1 1 1 1

Truth Table

ON-set

OFF-set

0 0 1 1 0 1 0 1

z

yx

Primes between

0-7

Venn Diagram

if(x,y,z == 000) then

P = 0

else if (x,y,z == 001) then

P = 0

else if (x,y,z == 010) then

P = 1

If or Case statement

Page 44: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Multi-output Functions• N-inputs, m-outputs

– Rather than simply T/F output, may want to produce a

set of signals (i.e. a multi-bit number, etc.)

• Write out all combos, interpret combos, then

write in answer

I3 I2 I1 C1 C0

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1

I3 I2 I1 C1 C0

0 0 0 0 0

0 0 1 0 1

0 1 0 0 1

0 1 1 1 0

1 0 0 0 1

1 0 1 1 0

1 1 0 1 0

1 1 1 1 1

I3 I2 I1 M1 M0

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1

I3 I2 I1 M1 M0

0 0 0 0 0

0 0 1 0 1

0 1 0 1 0

0 1 1 1 0

1 0 0 1 1

1 0 1 1 1

1 1 0 1 1

1 1 1 1 1

1’s Count of Input Max ON-input’s ID

Page 45: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Logic Function Examples

• Billy likes cheap, $5 pizzas.

$5 pizzas can have at most

one topping of Sausage,

Pepperoni, and Mushrooms.

But today only there was a

sale where a mushroom and

sausage pizza also $5. What

pizza’s can Billy get for $5

today? Describe this function

with a truth table and/or Venn

diagram.

Page 46: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

VENN DIAGRAMS

Page 47: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Venn Diagrams

• Graphical method of expressing a logic

function of 1-, 2-, or 3-variables

– Start with a box

– Add circles for each variable of the function

Page 48: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Single Variable Venn Diagram

• Let the circle represent the variable, x

– Area inside the circle represents x = ‘1’ = TRUE

– Area outside the circle represents x = ‘0’ = FALSE

x

Page 49: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Single Variable Venn Diagram

• Shade the areas where a function is true

• Area inside the circle represents where the

variable is true

x

This area is where X = 1

F = x

Page 50: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Single Variable Venn Diagram

• Area outside the circle represents where the

variable is false

x

This is where X = 0

F = X’

Page 51: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

2-Variable Venn Diagrams

• Add another circle for y

• Each disjoint region represents a distinct

combination of inputs (i.e. a minterm or maxterm)

x y

Page 52: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

2-Variable Venn Diagrams

• Add another circle for y

• Each disjoint region represents a distinct

combination of inputs (i.e. a minterm or maxterm)

X=1,Y=1

y

X=0,Y=0

X=0,Y=1X=1,Y=0

x

Page 53: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

2-Variable Venn Diagrams

F = X+Y

yx

F = X•Y

yx

Page 54: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

F=X’•Y (AND’ing Venn Diagrams)• Start with Venn Diagrams for individual parts (e.g. X’ separately

and Y separately)

• When AND’ing two Venn diagrams only shade areas that are shaded in ALL sub-diagrams

• Similar to “yellow and blue make green” principle

y x y

F = X’ • Y

X’ Y

x

yx

Page 55: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Venn Diagrams (OR’ing)

• When OR’ing two Venn diagrams shade all

areas that are shaded in ANY subdiagram

x y x y

x y

F = X+Y

x y

X Y

Page 56: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

UNUSED

Page 57: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Definitions of the Day

• Literal: A literal is an instance of a single variable or its complement.– Correct Examples: x, x’, y, ALARM, (LON)’

– Incorrect Examples: x+y, x’•y (these are expressions)

• Product Term: A logical product (AND’ing) of two or more literals …or…a

single literal by itself– Correct Examples: x’•y’•z, w’•x’•y, w•x’•a’b, c’

– Incorrect Examples: (x+y)•z•w, (x•y)’

– Only evaluates to ‘1’ for a single input combination

NOT (Inverter) AND

X ZX

YZ

YXZ ~XXXZ or or '

OR

ZX

Y

YXZ

Page 58: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Logic Function Domain

x

y

z

0 1

0 1

0 1

X Y Z

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1

z

yx

Truth Table

Binary

Decision Tree

Venn Diagram

Page 59: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

3-bit Prime Number Function

x

y

z

0 1

0 1

0 1

X Y Z P

0 0 0 0

0 0 1 0

0 1 0 1

0 1 1 1

1 0 0 0

1 0 1 1

1 1 0 0

1 1 1 1

X Y Z P

0 0 0 0

0 0 1 0

0 1 0 1

0 1 1 1

1 0 0 0

1 0 1 1

1 1 0 0

1 1 1 1

Truth Table

ON-set

OFF-set

0 0 1 1 0 1 0 1

z

yx

Primes between

0-7

Venn Diagram

Page 60: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

Logic Function Domainx

y

z

000 010

001 011

101 111

100 110

x

y

z

0 1

0 1

0 1

X Y Z

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1

z

yx

Truth Table Cube

Binary

Decision TreeVenn Diagram

Page 61: Lecture 3 Slides - University of Southern California · © Mark Redekopp, All rights reserved Lecture 3 Slides Logic Functions Signed Systems (Signed Magnitude, 2’s Complement)

© Mark Redekopp, All rights reserved

3-bit Prime Number Functionx

y

z

000 010

001 011

101 111

100 110

x

y

z

0 1

0 1

0 1

X Y Z P

0 0 0 0

0 0 1 0

0 1 0 1

0 1 1 1

1 0 0 0

1 0 1 1

1 1 0 0

1 1 1 1

z

yx

X Y Z P

0 0 0 0

0 0 1 0

0 1 0 1

0 1 1 1

1 0 0 0

1 0 1 1

1 1 0 0

1 1 1 1

Truth Table

ON-set

OFF-set

0

0

1

10

0

1 1

0 0 1 1 0 1 0 1

Primes between

0-7