Download Document

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
1. Digital Information: Number Systems
• Positional number systems:
– D = d1 d0 . d-1 d-2 = d1101 + d0100 + d-110-1 + d-210-2
– Here 10 is called base or radix.
– General form: (r>1 integer)
p 1
MSB
LSB
D   di r
i
i  n
– 100112 = 1*16 + 0*8 + 0*4 +1*2 + 1*1 = 1910
KU College of Engineering
Elec 204: Digital Systems Design
1
Octal and Hexadecimal Numbers
• Base 8 and 16 provide convenient shorthand
representation for multi-bit numbers in a digital
system.
–
–
–
–
–
–
Octal digit  3-bit string (0-7)
Hexadecimal digit  4-bit string (0-9, A-F)
1000110011102 = 43168 = 8CE16
10.10110010112 = 010.101 100 101 1002 = 2.54548
= 0010.1011 0010 11002 = 2.B2C16
In hexadecimal systems 2 digits represent an 8-bit byte.
KU College of Engineering
Elec 204: Digital Systems Design
2
Positional Number System Conversions
• Base-r-to-decimal conversions:
– (dp-1 ∙ ∙ ∙ d1 d0 . d-1 d-2 ∙ ∙ ∙ d-n )r
– r: base/radix
– p: digits to the left of radix point
– n: digits to the right of radix point
p 1
D   di r
i
i  n
• Eg:
– 436.58 = 4*82 + 3*81 + 6*80 + 5*8-1 = 286.62510
KU College of Engineering
Elec 204: Digital Systems Design
3
• Decimal-to-base-r conversion:
– 179 / 2 = 89 remainder 1 (LSB)
/ 2 = 44 rem 1
/ 2 = 22 rem 0
/ 2 = 11 rem 0
/ 2 = 5 rem 1
/ 2 = 2 rem 1
/ 2 = 1 rem 0
/ 2 = 0 rem 1 (MSB)
– Hence, 17910 = 101100112
KU College of Engineering
Elec 204: Digital Systems Design
4
Addition and Subtraction of Nondecimal
Numbers
• Addition
101111000
X
190 10111110
Y
141 10001101
___+______________
X+Y 331 101001011
Cin/bin X
Y
Cout
S
Bout
D
0
0
0
0
0
0
0
0
0
1
0
1
1
1
0
1
0
0
1
0
1
0
1
1
1
0
0
0
1
0
0
0
1
1
1
1
0
1
1
0
1
0
1
1
0
1
0
0
0
1
1
1
1
1
1
1
KU College of Engineering
Elec 204: Digital Systems Design
5
• Binary subtraction: (borrow, difference bits)
Bout
001111100
Minuend X
229
11100101
Subtrahend Y
46
00101110
_____________-_________________
Difference X-Y 183
10110111
– Use binary subtraction to compare numbers. If X-Y
produces a borrow out at the most significant bit, then
X is less than Y.
KU College of Engineering
Elec 204: Digital Systems Design
6
Representation of Negative Numbers
• Signed-Magnitude System/Representation:
– MSB: sign bit, 0: plus, 1: minus
010101012 = +8510
110101012 = -8510
011111112 = +12710
111111112 = -12710
000000002 = +010
100000002 = -010
– n-bit signed integer lies within –(2n-1-1) through +(2n-1-1)
with two representations of zero.
KU College of Engineering
Elec 204: Digital Systems Design
7
• Signed-magnitude adder
– If signs are same
add magnitudes, sign is same
else
compare magnitudes
subtract smaller from the larger
sign is sign of larger
• Signed-magnitude subtractor
– Change the sign of subtrahend, perform addition
KU College of Engineering
Elec 204: Digital Systems Design
8
Complement Number Systems
• Taking the complement is more difficult than
changing the sign, but in complement system
add/subt are easier.
• Radix complement of D: (-D) = rn – D
where D is an n-digit number
– If D is between 1 and rn-1
then D complement is between rn-1 and rn- (rn-1) = 1
– When D=0, D complement is rn, which is (n+1) digits,
hence D complement is also 0.
KU College of Engineering
Elec 204: Digital Systems Design
9
Two’s Complement
•
Radix complement for binary numbers
D: n bit binary number
(– D) = 2n – D = (2n-1) – D + 1
1710= 000100012
00002
11101110
+_______1
111011112 = -1710
1111
+___1
100002
–
–
–
–
The range of representable numbers: -(2n-1) – (2n-1-1)
A number is negative iff MSB is 1.
Zero (0) is positive, one extra negative number.
Decimal equivalent of two’s complement number is computed in
the same way for unsigned except MSB is (-2n-1), not (2n-1).
– Sign extension property: extend MSB for (n+1) bit number from n
bit number: 0110 = 00110 (5 bit), 1010 = 11010 (5 bit)
KU College of Engineering
Elec 204: Digital Systems Design
10
One’s Complement Representation
• One’s complement of D
-D = 2n - 1 – D
1710 = 000100012
111011102 = -1710
KU College of Engineering
Elec 204: Digital Systems Design
11
Two’s complement addition
-3 1101
+1 0001
-2 1110
-2 1110
+1 0001
-1 1111
-1 1111
+1 0001
0 10000
0000
• Subtract n (add –n)
– Add 16-n
– 16-n is 4-bit
two’s complement of n,
that is (-n).
1111
subt
-2
-1 0
0001
1
2
3
add
-7 -8 7 0111
1001 1000
KU College of Engineering
Elec 204: Digital Systems Design
12
Two’s complement subtraction
1 cin
+4 0100 0100
- +3 0011 1100
+1
10001
• Overflow
1
+3 0011 0011
- -4 1100 0011
+7
0111
– If the result exceeds the range of the number system
+5 0101
+ +6 0110
+11 1011 = -5
Overflow rule:
Addn: if the sign of the addends’ are same
and the sign of the sum is different from
addends’ sign.
KU College of Engineering
Elec 204: Digital Systems Design
13
Binary Multiplication
• Unsigned binary multiplication
– Shift and add multiplication
11 1011
x 13 1101
01011
00000
01011
1011
10001111
KU College of Engineering
Elec 204: Digital Systems Design
14
• Two’s complement multiplication
– Shift and two’s complement addition except for the last
step. Remember MSB represent (-2n-1)
-5 1011
x –3 1101
0000 initial partial product, which is zero.
1011
11011 partial product
0000
111011 partial product
1011
11100111
0101 shifted-and-negated
1 00001111
KU College of Engineering
Elec 204: Digital Systems Design
15
Binary division
• Shift and subtract with unsigned numbers
• No other easy way.
• So for signed numbers, take care of signs and
perform shift-and-subtract
KU College of Engineering
Elec 204: Digital Systems Design
16
BCD: Binary-Coded Decimal
• 0-9 encoded with their 4-bit unsigned binary representation
(0000 – 1001). The codewords (1010 – 1111) are not used.
• 8-bit byte represent values from 0 to 99.
• BCD Addition:
Carry
1
1
448
0100 0100 1000
+ 489
0100 1000 1001
937 Sum
1001 1101 10001
Add 6
+ 0110 + 0110
BCD sum
1 0011 1 0111
BCD result 1001
0011 0111
KU College of Engineering
Elec 204: Digital Systems Design
17
GRAY CODES
• As we count up and down using binary codes, the number of
bits that change from one to another varies.
• For Gray Codes, only 1 bit changes.
Decimal
8,4,2,1
Gray
0
1
2
3
4
5
6
7
8
9
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
0000
0100
0101
0111
0110
0010
0011
0001
1001
1000
KU College of Engineering
Elec 204: Digital Systems Design
18
Final Remark
Do not mix
(a) Conversion of a decimal number to a binary number
(b) Coding a decimal number with a binary number.
-
1410 = 11102 (This is conversion.) (a)
-
1410 => 0001 | 0100 (This is coding.) (b)
KU College of Engineering
Elec 204: Digital Systems Design
19