logic gates informatics info i101 february 3, 2003 john c. paolillo, instructor

37
Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Upload: andrea-quinn

Post on 17-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Logic Gates

Informatics INFO I101

February 3, 2003

John C. Paolillo, Instructor

Page 2: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Items for Today

• Last week– Digitization– Graphic, audio and video data sizes

• This time– Digital logic, Boolean algebra, and circuits– Logic gates and truth tables

Page 3: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

A Fundamental UnitySet Theory

&Logic

UnionIntersectionComplement

BooleanAlgebra

ORANDNOT

ElectricCircuits

ParallelSeries

Inversion

Binary Arithmetic

AdditionMultiplication

Twos Complement

Page 4: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Electric Circuits

+ off on

off off on

on on on

off on

off off off

on off on

Parallel Series

Page 5: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Binary Arithmetic

+ 0 1

0 00 01

1 01 10

0 1

0 0 0

1 0 1

Means zero, carry 1(two distinct outputs)

Page 6: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Boolean Algebra

+ 0 1

0 0 1

1 1 1

0 1

0 0 0

1 0 1

OR AND

0 1

0 0 1

1 1 0

Exclusive ORBinary addition:ExOR (for one’s place)plus AND (for carry)

Page 7: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

A Fundamental Unity

• Any logical or mathematical problem may be formulated in set theoretic terms

• Boolean logic may be used to represent any set-theoretic operation

• The fundamental elements of Boolean logic may be implemented in electric circuits

• Therefore, any logical or mathematical problem may be implemented in electrical circuits!

Page 8: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Logic Gates

Page 9: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

What are Logic Gates?

• Logic gates are conventional arrangements of switches that are treated as units

• They abstract away from the details of individual switches– They may be implemented in any number of

ways– Only their function is important

Page 10: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Symbols for Logic Gates

AND OR

XOR Not

Buff

Page 11: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Functions of Logic Gates

and 0 1

0 0 0

1 0 1

or 0 1

0 0 1

1 1 1

xor 0 1

0 0 1

1 1 0

nand 0 1

0 1 1

1 1 0

nor 0 1

0 1 0

1 0 0

xnor 0 1

0 1 0

1 0 1

A ¬A

0 1

1 0

A Buff

1 1

0 0

Page 12: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Boolean Logic Hints

AND: if you know that one input is 0, it doesn’t matter what the other input is, the output will be 0

OR: if you know that one input is 1, it doesn’t matter what the other input is, the output will always be 1

XOR: if you know that the inputs are the same, then the output will always be 0

Page 13: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Some Example Circuits

Page 14: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

XOR

E

A0101

B0011

C0111

D1110

E0110

D

A C

B

Page 15: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

De Morgan’s Law (1)

E

A0101

B0011

C1010

D1100

E0111

A C

BD

Page 16: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

De Morgan’s Law (2)

A0101

B0011

C1010

D1100

E0001

E

BD

A C

Page 17: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Encoding Position in a 2-by-2 Board

01 11

00 10

r1

r2

c1 c2

row

col

black

red

Page 18: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

01 11

00 10

r1

r2

c1 c2

col

row

Decoding Position to a 2-by-2 Board

Page 19: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

4-line multiplexer

d

c

b

a

C

A0101

B0011

CabcdA B

Page 20: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

4-line demultiplexer

A B

A0101

B0011

aIN000

b0

IN00

c00

IN0

d000

IN

IN

d

c

b

a

Page 21: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Other Applications of Boolean Logic

Page 22: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Graphic Paint/Copy Modes

COPY OR XOR

Page 23: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Database Search Queries

• A keyword represents the set of documents containing it

• Boolean AND represents the intersection of the sets corresponding to two (or more) search terms

• Boolean OR represents the union of the sets corresponding to two (or more) search terms

Page 24: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Addition: Half Adder

+ 00 01

00 00 01

01 01 10

S

A B

xor 0 1

0 0 1

1 1 0

and 0 1

0 0 0

1 0 1

C

The half adder sends a carry, but can’t accept one

+

Page 25: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Addition: Truth Tables

CI00001111

A01010101

B00110011

S COS01101001

CO00010111

Page 26: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Addition: Full Adder

A

B S

CO

CI

Page 27: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

More Digits

FullAdder

ci

co

s

ab

a0

s0

b0

FullAdder

ci

co

s

ab

a1

s1

b1

FullAdder

ci

co

s

ab

a2

s2

b2

FullAdder

ci

co

s

ab

a3

s3

b3

Full adders can be cascaded

Page 28: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Subtraction

Complement Representations

Page 29: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Subtraction

– 00 01

00 00 01

01 –01 00

• Subtraction is asymmetrical

• That makes it harder• We have to borrow

sometimes

Page 30: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Solution: “Easy Subtraction”

456–123333

999–123876

• Subtraction is easy if you don’t have to borrow

• i.e. if all the digits of the minuend are greater than (or equal to) all those of the subtrahend

• This will always be true if the minuend is all 9’s: 999, or 999999, or 9999999999 etc.

Page 31: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

How can we use easy subtraction?

• Subtract the subtrahend from 999 (or whatever we need) (easy)

• Add the result to the minuend (easy enough)• Add 1 (easy)• Subtract 1000 (not too hard)

Difference = Minuend + 999 – Subtrahend + 1 – 1000

This works for binary as well as decimal

Page 32: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Subtraction Example

10010101–01101110?????????

11111111–0110111010010001

This is the same as inverting each bit

+ 10010101100100110

+1100100111

–10000000000100111

Regular addition

Add one

Now drop the highest bit (easy: it’s out of range)

00100111

Page 33: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Subtraction Procedure

Invert each bit

Regular addition

Add one

Now drop the highest bit (easy: it’s out of range)

Each of these steps is a simple operation we can perform using our logic circuits

Bitwise XOR

Cascaded Adders

Add carry bit

Drop the highest bit (overflows)

Page 34: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Negative Numbers

Invert each bit

Add one

These steps make the negative of a number in twos-complement notation

• Twos complements can be added to other numbers normally• Positive numbers cannot use the highest bit (the sign bit)• This is the normal representation of negative numbers in binary

Page 35: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Counting

00000000 000000001 100000010 200000011 300000100 400000101 500000110 600000111 700001000 800001001 9

etc.

11111111 –111111110 –211111101 –311111100 –411111011 –511111010 –611111001 –711111000 –811110111 –911110110 –10etc.

Page 36: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor

Representations

• The number representation you use (encoding) affects the way you need to do arithmetic (procedure)

• This is true of all codes: encoding (representation) affects procedure (algorithm)

• Good binary codes make use of properties of binary numbers and digital logic

Page 37: Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor