Sie sind auf Seite 1von 25

CSE20 - Discrete Mathematics

Dr. Cynthia Bailey Lee Dr. Mia Minnes


csemoodle.ucsd.edu ted.ucsd.edu and www.math.ucsd.edu/~minnes/cse20 and minnes@math.ucsd.edu

iClicker frequency BB

Minnes (CSE20)

6/3/2013

1 / 14

Todays topics

Logic gates
Converting between propositions and hardware

Computer arithmetic
Adding two 1-digit binary numbers Adding two 4-digit binary numbers

Minnes (CSE20)

6/3/2013

2 / 14

Logic gates for computer hardware

In the diagrams, can abbreviate negations by a circle.

Minnes (CSE20)

6/3/2013

3 / 14

Example: implication

How do we implement the implication connective in hardware? Recall: pq Try to draw it! p q

Recall: Using DeMorgan, we could equivalently write pq (p q )

Minnes (CSE20)

6/3/2013

4 / 14

Hardware simplication by logic simplication


As electrical signal propagates from left to right through the circuit, delay is introduced by each gate . This delay limits the number of cycles that can be performed each second: the GHz of clock. Each gate also takes up surface on the chip. And generates heat. Better to minimize number of gates and wires.

Minnes (CSE20)

6/3/2013

5 / 14

Hardware simplication by logic simplication


As electrical signal propagates from left to right through the circuit, delay is introduced by each gate . This delay limits the number of cycles that can be performed each second: the GHz of clock. Each gate also takes up surface on the chip. And generates heat. Better to minimize number of gates and wires. For example: (p q ) (p q ) Can be expressed in a logical circuit after we translate to: (p q ) (p q ) Which is equivalent (using DeMorgan and the distributivity) to (p q ) (p q ) p (q q ) p
Minnes (CSE20) 6/3/2013 5 / 14

Review: DNF
What hardware logic implements this truth table? p T T T T F F F F q T T F F T T F F r T F T F T F T F ? T F F T F T F T

Minnes (CSE20)

6/3/2013

6 / 14

Review: DNF
What hardware logic implements this truth table? p T T T T F F F F q T T F F T T F F r T F T F T F T F ? T F F T F T F T

What DNF proposition is equivalent to the left-most column? *A. (p q r ) (p q r ) (p q r ) (p q r ) B. (p q r ) (p q r ) (p q r ) (p q r ) C. (p q r ) (p q r ) (p q r ) (p q r ) D. (p q r ) (p q r ) (p q r ) (p q r )


Minnes (CSE20) 6/3/2013 6 / 14

DNF in hardware logic

DNF is (p q r ) (p q r ) (p q r ) (p q r ) Which hardware logic works? Try to draw it !

Minnes (CSE20)

6/3/2013

7 / 14

DNF in hardware logic

DNF is (p q r ) (p q r ) (p q r ) (p q r ) Which hardware logic works? Try to draw it ! Using 2-input gates for 3-input propositions: Theorem. p q r = p (q r ) Associativity

Minnes (CSE20)

6/3/2013

7 / 14

Computer arithmetic
When realize logic propositions/ calculations on a computer, need to implement using gates and voltages. Binary values: 0 and 1

Minnes (CSE20)

6/3/2013

8 / 14

Computer arithmetic
When realize logic propositions/ calculations on a computer, need to implement using gates and voltages. Binary values: 0 and 1 Interpretation of these values depends on context? In Logic:
1b = True 0b = False

In Arithmetic i.e. binary numbers (unsigned):


0b = 0d 1b = 1d 10b = 2d 11b = 3d 100b = 4d In general, (bn bn1 b1 b0 )b = bn 2n + bn1 2n1 + + b1 2 + b0
Minnes (CSE20) 6/3/2013 8 / 14

Converting from (unsigned) binary to decimal

Multiply each bit by appropriate power of 2. E.g. 1001010100b = 1 29 + 0 28 + 0 27 + 1 26 + 0 25 + 1 24 + 0 23 + 1 2 = 512 + 64 + 16 + 4 = 596.

Minnes (CSE20)

6/3/2013

9 / 14

Converting from decimal to (unsigned) binary


Algorithm. Input: decimal number N Initialize n = N current number that needs to be represented While n > 1

List all powers of 2 until nd largest one, 2k , that is smaller than N .


E.g. 20 = 1, 21 = 2, 22 = 4, 23 = 8, 24 = 16, 25 = 32, 26 = 64, 27 = 128, 28 = 256, 29 = 512, 210 = 1024, . . .

Put a 1 in the k s place of the binary representation. Update n = N 2k .

If n = 1, put a 1 in the 0 place of the binary representation. Put 0s in all places that havent been set to 1. If N = 0, erase all leading 0s. If N = 0, erase all but one 0s.

Minnes (CSE20)

6/3/2013

10 / 14

Converting from decimal to (unsigned) binary


Algorithm. Input: decimal number N Initialize n = N current number that needs to be represented While n > 1

List all powers of 2 until nd largest one, 2k , that is smaller than N .


E.g. 20 = 1, 21 = 2, 22 = 4, 23 = 8, 24 = 16, 25 = 32, 26 = 64, 27 = 128, 28 = 256, 29 = 512, 210 = 1024, . . .

Put a 1 in the k s place of the binary representation. Update n = N 2k .

If n = 1, put a 1 in the 0 place of the binary representation. Put 0s in all places that havent been set to 1. If N = 0, erase all leading 0s. If N = 0, erase all but one 0s. What is binary representation of 17d ? A. 17b B. 10b C. 101b
Minnes (CSE20) 6/3/2013 10 / 14

D. 1001b *E. 10001b

Adding . . . using carry

Carry is when the sum in one column exceeds the maximum digit Max digit in decimal is 9 Max digit in binary is 1 and must overow into the next column.

Minnes (CSE20)

6/3/2013

11 / 14

Adding . . . using carry

Carry is when the sum in one column exceeds the maximum digit Max digit in decimal is 9 Max digit in binary is 1 and must overow into the next column. In decimal: e.g. 5823 +3 5 5 1

Minnes (CSE20)

6/3/2013

11 / 14

Adding . . . using carry

Carry is when the sum in one column exceeds the maximum digit Max digit in decimal is 9 Max digit in binary is 1 and must overow into the next column. In decimal: e.g. 5823 +3 5 5 1 9374

Minnes (CSE20)

6/3/2013

11 / 14

Adding . . . using carry


Carry is when the sum in one column exceeds the maximum digit Max digit in decimal is 9 Max digit in binary is 1 and must overow into the next column. In decimal: e.g. 5823 +3 5 5 1

In binary: e.g. 1101 +0 1 1 0

Minnes (CSE20)

6/3/2013

11 / 14

Adding . . . using carry


Carry is when the sum in one column exceeds the maximum digit Max digit in decimal is 9 Max digit in binary is 1 and must overow into the next column. In decimal: e.g. 5823 +3 5 5 1

In binary: e.g. 1101 +0 1 1 0 10011


Minnes (CSE20) 6/3/2013 11 / 14

Double check
In previous examples, what are numbers in decimal?

1101b +0 1 1 0 b 10011b A. 110d + 110d = 100011d B. 12d + 4d = 16d C. 15d + 8d = 23d *D. 13d + 6d = 19d E. None of the above.

Minnes (CSE20)

6/3/2013

12 / 14

Designing adder hardware

Can represent each column in the long addition of binary number using a truth table: p 0 0 1 1 q 0 1 0 1 Will we have a carry? p+q

Minnes (CSE20)

6/3/2013

13 / 14

Designing adder hardware

Can represent each column in the long addition of binary number using a truth table: p 0 0 1 1 q 0 1 0 1 Will we have a carry? 0 0 0 p+q 0 1 1

Minnes (CSE20)

6/3/2013

13 / 14

Designing adder hardware

Can represent each column in the long addition of binary number using a truth table: p 0 0 1 1 q 0 1 0 1 Will we have a carry? 0 0 0 1 p+q 0 1 1 0

Minnes (CSE20)

6/3/2013

13 / 14

Designing adder hardware

Can represent each column in the long addition of binary number using a truth table: Which hardware implements addition? Carry: p q Sum: p q (XOR)

Minnes (CSE20)

6/3/2013

13 / 14

Das könnte Ihnen auch gefallen