Professional Documents
Culture Documents
iClicker frequency BB
Minnes (CSE20)
6/5/2013
1 / 16
Todays topics
Computer arithmetic
Adding two 1-digit binary numbers Adding two 4-digit binary numbers
Minnes (CSE20)
6/5/2013
2 / 16
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/5/2013
3 / 16
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/5/2013
3 / 16
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/5/2013
3 / 16
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
Minnes (CSE20)
6/5/2013
3 / 16
Minnes (CSE20)
6/5/2013
4 / 16
Minnes (CSE20)
6/5/2013
4 / 16
Minnes (CSE20)
6/5/2013
4 / 16
Minnes (CSE20)
6/5/2013
4 / 16
Minnes (CSE20)
6/5/2013
4 / 16
Minnes (CSE20)
6/5/2013
4 / 16
We can write down logic propositions for each of the output columns: cout = p+q =
Minnes (CSE20) 6/5/2013 4 / 16
We can write down logic propositions for each of the output columns: cout = (p q cin ) (p (q cin )) p+q =
Minnes (CSE20) 6/5/2013 4 / 16
We can write down logic propositions for each of the output columns: cout = (p q cin ) (p (q cin )) (q cin ) (p (q cin )) p+q =
Minnes (CSE20) 6/5/2013 4 / 16
We can write down logic propositions for each of the output columns: cout = (p q cin ) (p (q cin )) (q cin ) (p (q cin )) p + q = (p q ) cin
Minnes (CSE20) 6/5/2013 4 / 16
Logic propositions have many equivalent forms. However, some lend themselves better to reuse. cout = (q cin ) (p (q cin )) p + q = (p q ) cin
Minnes (CSE20)
6/5/2013
5 / 16
Logic propositions have many equivalent forms. However, some lend themselves better to reuse. cout = (q cin ) (p (q cin )) (p q ) p + q = (p q ) cin (p q ) cin
Minnes (CSE20)
6/5/2013
5 / 16
Minnes (CSE20)
6/5/2013
5 / 16
Hexadecimal
Number systems pros and cons: Decimal
Pros familiar, relatively concise Cons Hard to translate to signals Cons Verbose
Binary
Pros compatible with logic, circuits
For example, the number 1000 uses 4 digits but would require 9 bits: 1000d = 1111101000b
Minnes (CSE20)
6/5/2013
6 / 16
Hexadecimal
Number systems pros and cons: Decimal
Pros familiar, relatively concise Cons Hard to translate to signals Cons Verbose
Binary
Pros compatible with logic, circuits
For example, the number 1000 uses 4 digits but would require 9 bits: 1000d = 1111101000b Hexadecimal system is base 16. Notation: number in hex starts with 0x . Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B , C , D , E , F Since 16 = 24 , one hex digit replaces 4 binary digits.
Minnes (CSE20) 6/5/2013 6 / 16
Number systems
Decimal
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Minnes (CSE20)
Hex
0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13
Binary
0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111 11000 11001 11010 11011
6/5/2013 7 / 16
Hexadecimal example
Minnes (CSE20)
6/5/2013
8 / 16
One option:
Use unsigned representation for the absolute value of the number. Have an additional ag bit with 1 meaning the number is negative and 0 meaning the number is positive. Problem: circuits for arithmetic get really messy!
Minnes (CSE20)
6/5/2013
9 / 16
One option:
Use unsigned representation for the absolute value of the number. Have an additional ag bit with 1 meaning the number is negative and 0 meaning the number is positive. Problem: circuits for arithmetic get really messy!
Minnes (CSE20)
6/5/2013
9 / 16
Twos complement
For N Z in decimal notation: If N 0, use unsigned notation to compute twos complement. If N < 0,
Write |N | in unsigned binary Insert additional 0 in front (as most signicant bit) Flip all the bits Add 1.
Minnes (CSE20)
6/5/2013
10 / 16
Minnes (CSE20)
6/5/2013
11 / 16
What is twos complement notation for 100? Write | 100| in unsigned binary 100 d = Insert additional 0 in front (as most signicant bit) Flip all the bits Add 1.
Minnes (CSE20)
6/5/2013
11 / 16
What is twos complement notation for 100? Write | 100| in unsigned binary 100 d = 1100100 b Insert additional 0 in front (as most signicant bit) Flip all the bits Add 1.
Minnes (CSE20)
6/5/2013
11 / 16
What is twos complement notation for 100? Write | 100| in unsigned binary 100 d = 1100100 b Insert additional 0 in front (as most signicant bit) 01100100 Flip all the bits Add 1.
Minnes (CSE20)
6/5/2013
11 / 16
Minnes (CSE20)
6/5/2013
12 / 16
Minnes (CSE20)
6/5/2013
13 / 16
Minnes (CSE20)
6/5/2013
13 / 16
Minnes (CSE20)
6/5/2013
13 / 16
Proof
Theorem For all m 1, n 1, b0 , . . . , bn {0, 1}, 1m bn b0 b = 1bn b0 b . Proof. By induction on m. Base step:
Minnes (CSE20)
6/5/2013
14 / 16
Proof
Theorem For all m 1, n 1, b0 , . . . , bn {0, 1}, 1m bn b0 b = 1bn b0 b . Proof. By induction on m. Base step:
Minnes (CSE20)
6/5/2013
14 / 16
Proof
Theorem For all m 1, n 1, b0 , . . . , bn {0, 1}, 1m bn b0 b = 1bn b0 b . Proof. By induction on m. Base step: (m = 1)
WTS n 1b1 , . . . , bn {0, 1} (1bn b0 = 1bn b0 ) Let n 1, b1 . . . , bn {0, 1} then 1 bn b0 = 1 bn b0
Minnes (CSE20)
6/5/2013
14 / 16
Proof
Theorem For all m 1, n 1, b0 , . . . , bn {0, 1}, 1m bn b0 b = 1bn b0 b . Proof. By induction on m. Base step: Induction step: Let m 1.
Assume that for all r 1, c0 , . . . , cr {0, 1}, 1m cn c0 = 1cn c0 . WTS works for m + 1 Let n 1 and let b0 , . . . , bn {0, 1}. Then Ind Assum 1m+1 bn b0 = 1m 1bn b0 = 11bn b0 .
Minnes (CSE20)
6/5/2013
14 / 16
Proof
Theorem For all m 1, n 1, b0 , . . . , bn {0, 1}, 1m bn b0 b = 1bn b0 b . Proof. By induction on m. Base step: Induction step: Let m 1.
Assume that for all r 1, c0 , . . . , cr {0, 1}, 1m cn c0 = 1cn c0 . WTS works for m + 1 Let n 1 and let b0 , . . . , bn {0, 1}. Then Ind Assum = 11bn b0 . 1m+1 bn b0 = 1m 1bn b0 By denition of twos complement, this has value: 2n+2 + 2n+1 + bn 2n + + b0 But, 2n+2 + 2n+1 = 2n+1 (2 + 1) = 2n+1 .
Minnes (CSE20)
6/5/2013
14 / 16
Proof
Theorem For all m 1, n 1, b0 , . . . , bn {0, 1}, 1m bn b0 b = 1bn b0 b . Proof. By induction on m. Base step: Induction step: Let m 1.
Assume that for all r 1, c0 , . . . , cr {0, 1}, 1m cn c0 = 1cn c0 . WTS works for m + 1 Let n 1 and let b0 , . . . , bn {0, 1}. Then Ind Assum = 11bn b0 . 1m+1 bn b0 = 1m 1bn b0 By denition of twos complement, this has value: 2n+2 + 2n+1 + bn 2n + + b0 But, 2n+2 + 2n+1 = 2n+1 (2 + 1) = 2n+1 . So, 1m+1 bn b0 = 2n+1 + bn 2n + + b0 . This is exactly the value of 1bn b0 (in twos complement)!
Minnes (CSE20)
6/5/2013
14 / 16
Signed arithmetic
Goal: a + (b ) = a b .
Minnes (CSE20)
6/5/2013
15 / 16
Signed arithmetic
Goal: a + (b ) = a b . Twos complement makes this work! For example, consider 10011011 + 01001001
Minnes (CSE20)
6/5/2013
15 / 16
Signed arithmetic
Goal: a + (b ) = a b . Twos complement makes this work! For example, consider 10011011 + 01001001 11100100
Minnes (CSE20)
6/5/2013
15 / 16
Signed arithmetic
Goal: a + (b ) = a b . Twos complement makes this work! For example, consider 10011011 + 01001001 11100100 Converting each line to decimal:
Minnes (CSE20)
6/5/2013
15 / 16
Signed arithmetic
Goal: a + (b ) = a b . Twos complement makes this work! For example, consider 10011011 + 01001001 11100100 Converting each line to decimal: (128 + 16 + 8 + 2 + 1) + (64 + 8 + 1)
Minnes (CSE20)
6/5/2013
15 / 16
Signed arithmetic
Goal: a + (b ) = a b . Twos complement makes this work! For example, consider 10011011 + 01001001 11100100 Converting each line to decimal: 101 + 73
Minnes (CSE20)
6/5/2013
15 / 16
Signed arithmetic
Goal: a + (b ) = a b . Twos complement makes this work! For example, consider 10011011 + 01001001 11100100 Converting each line to decimal: 101 + 73 28
Minnes (CSE20)
6/5/2013
15 / 16
Signed arithmetic
Goal: a + (b ) = a b . Twos complement makes this work! For example, consider 10011011 + 01001001 11100100 Converting each line to decimal: 101 + 73 28 Does 11100100b = 28d ? *A. Yes B. No C. ????
Minnes (CSE20) 6/5/2013 15 / 16
Shirt ...
Minnes (CSE20)
6/5/2013
16 / 16