principles of digital design
Post on 22-Nov-2014
269 Views
Preview:
TRANSCRIPT
1
1
PowerPoint Slidesto accompany
Digital Principles and DesignDonald D. Givone
Chapter 2Number Systems, Ar ithmetic,
and Codes
2
2.1 positional number systems
n 872.64 = 800 + 70 + 2 + 0.6 + 0.04n =8*102 + 7*101 + 2*100 + 6*10-1 +
4*10-2
n Radix-weighted positional number systemor called positional number systemn 表達一個 number 的方法
n 有一組有限符號的集合 called digitsn 每一個 digit 都是 nonnegative integer
3
2.1
n N = dn-1dn-2… d1d0. d-1… d-m
n = dn-1*rn-1 + dn-2*rn-2 + … d1*r1 + d0*r0 + d-
1*r-1 + … d-m*r-m ,0<= di <=(r-1)n r is the base of number systemn n是N的整數部分 digits 的個數n m是N的小數部分 digits 的個數n order是每一個 digit 的 power of basen n=0 – 0th-order digitn n=1 – 1th-order digit…
4
Table 2.1
n Base Number system Digit symbolsn 2 Binary 0,1n 3 Ternary 0,1,2n 4 Quaternary 0,1,2,3n 5 Quinary 0,1,2,3,4n 8 Octal 0,1,2,3,4,5,6,7n 10 Decimal 0,1,2,3,4,5,6,7,8,9n 12 Duodecimal 0,1,2,3,4,5,6,7,8,9,A,Bn 16 Hexadecimal 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
5
Table 2.2
n Decimal Binary Ternary Octal Hexadecimaln 0 0 0 0 0n 1 1 1 1 1n 2 10 2 2 2n 3 11 10 3 3n 4 100 11 4 4n 5 101 12 5 5n 6 110 20 6 6n 7 111 21 7 7n 8 1000 22 10 8n 9 1001 100 11 9n 10 1010 101 12 An 11 1011 102 13 B
6
2.3 basic arithmetic operations
n Additionn Subtractionn Multiplicationn Division
2
7
2.3.1 addition
n 1(2) + 1 (2) = 10 (2)
8
Example 2.1n Binary n 11 = carriesn 11010= augendn + 11001= addendn ============n 110011= sum
9
Example 2.1n Binary n 1 1 = carriesn 11.01= augendn + 10.01= addendn ============n 101.10= sum
10
Example 2.2
n Ternaryn 11 = carriesn 1102= augendn + 1022= addendn ============n 2201= sum
11
Example 2.2
n Ternaryn 11 1 = carriesn 1201.2= augendn + 1200.1= addendn ============n 10102.0= sum
12
2.3.2 subtraction
n The inverse operation of addition is subtraction
3
13
Table 2.3
n a + b (binary)n 0 + 0 = 0n 0 + 1 = 1n 1 + 0 = 1n 1 + 1 = 0 and carry 1
0 and carry 1
1a=110a=0b=1b=0a + b
14
Table 2.3
n a + b (ternary)
0 and carry 1
21a=1
1 and carry 1
2b=2
0 and carry 1
2a=2
10a=0b=1b=0a + b
15
Table 2.4
n a - b (binary)n 0 - 0 = 0n 0 - 1 = 1 and borrow 1n 1 - 0 = 1n 1 - 1 = 0
01a=1
1 and borrow 1
0a=0b=1b=0a - b
16
Table 2.4
n a - b (ternary)
2 and borrow 1
01a=1
0
1 and borrow 1
b=2
12a=2
2 and borrow 1
0a=0b=1b=0a - b
17
Example 2.3n a – b (binary)
n 10001 = minuendn - 1011 = subtrahendn -------------------------n 110 = difference
n 02001 ó 01201 ó 01121n 01121n - 1011n ---------n 00110
18
Example 2.3n a – b (ternary)
n 2102 = minuendn -1021 = subtrahendn -------------------------n 1011 = difference
n 2102 ó 2032 n 2032 = minuendn -1021 = subtrahendn -------------------------n 1011 = difference
4
19
2.3.3 multiplication
20
Example 2.5n 10.11 = multiplicandn * 1 01 = multipliern -------------------------------n 10 11n 000 0n 1011n ------------------------------n 1101.11 = product
Array of partial prodcts
21
Table 2.5
n a*b (binary)
10a=100a=0b=1b=0a * b
22
Table 2.5
n a*b (ternary)n 2 * 2 = 4 = 3 + 1 = 1 and carry 1
210a=1
1 and carry 1
0b=2
20a=2
00a=0b=1b=0a * b
23
2.3.4 division
n The process consists of multiplications and subtractions
24
Example 2.7n Ternary n 102 = quotientn Divisor = 12 2010 = dividendn -12n 11n -00n 110n -101 ó -24 ó -31 ó -101n 2 = remainder
5
25
Methods of number conversion
n Two basic procedures for converting numbers in one number system into another number systemn Polynomial method
n 將 base-r 所表達的 number => decimal number system 較好用
n Iterative methodn 將 decimal number system => base-r 所表達的
number 較好用,但是整數與小數部分需要分開處理
26
2.4 polynomial method of number conversion
n Base-r1 所表示的number system:n N(r1) = (dn-1dn-2… d1d0. d-1… d-m)(r1),0<= di
<=(r1-1)n N(r1) = dn-1(r1)*r1n-1
(r1) + dn-2(r1)*r1n-2(r1) +..+ d-
m(r1)*r1-m(r1) .
n = dn-1(r1)*10n-1(r1) + dn-2(r1)*10n-2
(r1) + d-m(r1)*10-
m(r1) .
n N(r2) = dn-1(r2)*r1n-1(r2) + dn-2(r2)*r1n-2
(r2) +..+ d-
m(r2)*r1-m(r2) .
n r1(r2) 為 r1(r1) 轉成以 base-r2 的表示法,d 亦同
27
Example
n 1101(2) = n 1(2)*103
(2)+1(2)*102(2)+0(2)*101
(2)+1(2)*100(2)
n 1(10)*23(10)+1(10)*22
(10)+0(10)*21(10)+1(10)*20
(10)
n = 8 + 4 + 0 + 1n = 13(10) .
28
Example 2.9
n Binary => decimaln 101.011(2) = 1(2)*102
(2) + 0(2)*101(2) +
1(2)*100(2) + 0(2)*10-1
(2) + 1(2)*10-2(2) +
1(2)*10-3(2).
n = 1(10)*22(10) + 0(10)*21
(10) + 1(10)*20(10) +
0(10)*2-1(10) + 1(10)*2-2
(10) + 1(10)*2-3(10).
n = 4 + 0 + 1 + 0.5 + 0.25 + 0.125n = 5.375(10) .
29
Example 2.10n Ternary => decimaln 201.1(3) = 2(3)*102
(3) + 0(3)*101(3) +
1(3)*100(3) + 1(3)*10-1
(3) .n = 2(10)*32
(10) + 0(10)*31(10) + 1(10)*30
(10) + 1(10)*3-1
(10) .n = 18 + 0 + 0.333…n = 19.33...n 在轉換過程中,有可能需要較多的 digits
數目才能保證轉換後的 精確度30
Example 2.11
n Decimal => binaryn 113.5(10) = 1(10)*102
(10) + 1(10)*101(10) +
3(10)*100(10) + 5(10)*10-1
(10) .n = 1(2)*10102
(2) + 1(2)*10101(2) +
11(2)*10100(2) + 101(2)*1010-1
(2) .n = 1100100 + 1010 + 11 + 0.1n = 1110001.1(2).n 101(2)*1010-1
(2) => ? 下頁說明
6
31
Example 2.11
n 101(2)*1010-1(2)
n = 101/1010n 0.1n 1010 101 0n 101 0n 0n 10102
(2) => 1010*1010 = 1100100
32
Example 2.12
n Binary => ternaryn 11010(2) = 1(2)*104
(2) + 1(2)*103(2) +
0(2)*102(2) + 1(2)*101
(2) +0(2)*100(2) .
n = 1(3)*24(3) + 1(3)*23
(3) + 0(3)*22(3) +
1(3)*21(3) +0(3)*20
(3) .n = 121 + 22 + 0 + 2 + 0n = 222(3).
33
Example 2.13
n Ternary => binaryn 2102(3) = 2(3)*103
(3) + 1(3)*102(3) +
0(3)*101(3) + 2(3)*100
(3) .n = 10(2)*113
(2) + 1(2)*112(2) + 0(2)*111
(2) + 10(2)*110
(2) .n = 110110 + 1001 + 0 + 10n = 1000001(2).
34
2.5 iterative method of number conversion
n 將一數由 base-r1 => base-r2n 將此數 除以 r2(r1) .n 所得餘數 就是單一 digitn 先得的是 LSB
35
Example 2.14n Decimal => binaryn 43(10) = ?(2) =
n 43(10) / 2(10) = 21(10) .餘 1(10) = 1(2) =0th-order digitn 21(10) / 2(10) = 10(10) .餘 1(10) = 1(2) =1th-order digitn 10(10) / 2(10) = 5(10) ..餘 0(10) = 0(2) =2th-order digitn 5(10) / 2(10) = 2(10) ..餘 1(10) = 1(2) =3th-order digitn 2(10) / 2(10) = 1(10) ..餘 0(10) = 0(2) =4th-order digitn 1(10) / 2(10) = 0(10) ..餘 1(10) = 1(2) =5th-order digit
n 43(10) = 101011(2) . Stop
36
Example 2.15
n Decimal => hexadecimaln 213(10) = ?(16) =
n 213(10) / 16(10) = 13(10) .餘 5(10) = 5(16) =0th-order digit
n 13(10) / 16(10) = 0(10) .餘 13(10) = D(16) =1th-order digit
n 213(10) = D5(16) . Stop
7
37
Example 2.16
n Binary => decimaln Conversion of 1001011(2) into its decimal
equivalent by the iterative methodn 1001011(2)/1010(2) = 111(2) + 101(2); 101(2) =
5(10) = 0th-order digitn 111(2)/1010(2) = 0(2) + 111(2); 111(2) = 7(10).=
1th-order digitn 1001011(2) = 75(10) ;
38
2.5.3 iterative method for converting fractions
n Conversion of fraction number N1(r1) into its equivalent number N2(r2) .n N1(r1)* r2(r1) = A.B(r1) ; A (r1) = A (r2) =Most
significant fraction digitn B(r1)* r2(r1) = A’.B’(r1) ; A’(r1) = A’(r2) ;n …n B’(r1)* r2(r1) = C.0000(r1) ; C(r1) = C(r2) = Least
significant fraction digitn 有限digit轉換後,不見得仍是有限digit
Stop
39
Example 2.17
n Conversion of 0.8125(10) into its equivalent binary fractionn 0.8125(10)* 2(10) = 1 .6250(10) ; 1 (10) = 1 (2)
=Most significant fraction digitn 0.6250(10)* 2(10) = 1 .2500(10) ; 1 (10) = 1 (2) ;n 0.2500(10)* 2(10) = 0 .5000(10) ; 0 (10) = 0 (2) ;n 0.5000(10)* 2(10) = 1 .0000(10) ; 1 (10) = 1 (2) =
Least significant fraction digitn 0.8125(10) = 0.1101(2) ;
Stop
40
Example 2.18n Conversion of 0.1011(2) into its equivalent
decimal fractionn 0.1011(2)* 1010(2) = 110.1110(2) ; 110 (2) = 6 (10)
=Most significant fraction digitn 0.1110(2)* 1010(2) = 1000.1100(2) ; 1000 (2) = 8 (10);n 0.1100(2)* 1010(2) = 111.1000(2) ; 111 (2) = 7 (10);n 0.1000(2)* 1010(2) = 101.0000(2) ; 101 (2) = 5 (10) =
Least significant fraction digitn 0.1011(2) = 0.6875(10) ;
Stop
41
2.5.5 a final example
n 整數與小數要分開來轉換處理n 中間用小數點連接
42
Example 2.19n Conversion of 201.12(3) into its binary
equivalent n 201(3) / 2(3) = 100(3) .餘 1(3) = 1(2) =0th-order
digitn 100(3) / 2(3) = 11(3) .餘 1(3) = 1(2) =1th-order
digitn 11(3) / 2(3) = 2(3) .餘 0(3) = 0(2) =2th-order digitn 2(3) / 2(3) = 1(10) .餘 0(3) = 0(2) =3th-order digitn 1(3) / 2(3) = 0(3) .餘 1(3) = 1(2) =4th-order digitn 201(3) = 10011(2) . Stop
8
43
Example 2.19n 0.12(3) * 2(3) = 1.01(3); 1(3) = 1(2) =Most
significant fraction digitn 0.01(3) * 2(3) = 0.02(3); 0(3) = 0(2)
n 0.02(3) * 2(3) = 0.11(3); 0(3) = 0(2)
n 0.11(3) * 2(3) = 0.22(3); 0(3) = 0(2)
n 0.22(3) * 2(3) = 1.21(3); 1(3) = 1(2)
n 0.21(3) * 2(3) = 1.12(3); 1(3) = 1(2)
n 0.12(3) = 0.100011(2) . Repeating, as 0.12 appear again
44
Example 2.19
n 201.12(3) = 10011.100011(2) .
repeating
45
2.6 special conversion proceduresn 當1數在2種base 間轉換時,若此2種base
間有指數的關係時n 8 = 23,16 = 24,n 從小數點起,向左及向右,數個bits為一組,
開始轉換。n 11111101.0011(2) 分組成如:
011111101.001100(2) ;n 3 7 5 . 1 4(8) ;n 1 7 3 . 2 4(8) 可轉換成n 001111011.010100(2) ;
46
Base 2與 base 8轉換的證明n 若 N(2) = … d8d7… d1d0.d-1d-2d-3…
n = … d8*28 + d7*27 + d6*26 + d5*25 + d4*24 + d3*23 + d2*22 + d1*21 + d0*20 + d-1*2-1 + d-
2*2-2 + d-3*2-3 + …n = … + (d8*22 + d7*21 + d6)*26 + (d5*22 +
d4*21 + d3)*23 + (d2*22 + d1*21 + d0) *20 + (d-1*22 + d-2*21 + d-3) *2-3 + …
n = … + (d8*22 + d7*21 + d6)*82 + (d5*22 + d4*21 + d3)*81 + (d2*22 + d1*21 + d0) *80 + (d-1*22 + d-2*21 + d-3) *8-1 + …
47
2.6 special conversion proceduresn 001010110110.1110(2)
n = 2 B 6 . E(16) ;n 3 A B . 2(16)
n = 001110101011.0010(2) ;
48
2.7 signed numbers and complements
n Signed-magnitude:n 用1個符號代替(+) 、(-)號
n Binary digit 0 代表(+) n Binary digit 1 代表(-)
9
49
Graphical interpretation of sign-magnitude numbers
n 向右為正,向左為負
50
Graphical interpretation of complements
n Offset origin放置於 true origin左邊夠遠處n 負數自true origin向右量出大小n 如: *7,*5,*2 n 同一點由true origin看成
N1,但由offset origin看去卻是N2
n N2 is called the complement(補數) of N1
n N1 + N2 得一特殊值
51
Graphical interpretation of complements
n N1 + N2 得一特殊值n 此特殊值就是 offset origin與 true origin之
間的距離(displacement)
52
2.7
n 例如: 7 is the complement of 3n 7 + 3 = 10 ó base is 10
53
Complement n r’s-complement
n or called radix complement or called true complementn offset origin 與 true origin之間的距離 = rn 單位.n In decimal number called 10’s-補,for binary system
called 2’s補n (r-1)’s-complement
n or called diminished-radix complementn or called radix-minus-one complementn offset origin 與 true origin之間的距離 = rn – r-m 單位.n In decimal number called 9’s-補,for binary system
called 1’s補
54
Complement
n rn – r-m 個單位.n r 是在自己數字系統中 base 數字的表示法
n 例如: r = 10
n n 是整數digit中最多的位數個數n 145,n = 3; 2974,n = 4; 365 - 29,n = 3;
n m 是小數部分digit中最多的位數個數n 0.34,m = 2; 0.1 – 0.234,m = 3;
10
55
Complement
n r’s-complement of N = rn – Nn (r-1)’s-complement of N = rn – r-m - Nn r 是在自己數字系統中 base 數字的表示法
n 例如: r = 10
n n 是整數digit中最多的位數個數n 145,n = 3; 2974,n = 4; 365 - 29,n = 3;
n m 是小數部分digit中最多的位數個數n 0.34,m = 2; 0.1 – 0.234,m = 3;
56
Table 2.6 representations of signed numbers
n Positive numbersn All representations: 0N
n Negative numbersn Sign-magnitude: 1Nn Signed r’s-補: 1(rn – N)n Signed (r-1)’s-補: 1(rn – r-m - N)
0: 正數1: 負數
57
Example 2.20
n Find the 10’s-complement of the unsigned decimal number 123.45n Unsigned: 103 – 123.45 = 876.55n Signed :(負數) 1876.55
58
Example 2.21
n Find the 9’s-complement of the unsigned decimal number 123.45n Unsigned: 103 – 10-2 - 123.45 = 999.99 –
123.45 = 876.54n Signed :(負數) 1876.54
59
Example 2.22
n Find the 2’s-complement of unsigned binary number 1101.011n Unsigned: 104
(2) – 1101.011(2) = 10000 –1101.011 = 0010.101
n Signed :(負數) 10010.101
60
Example 2.23
n Find the 1’s-complement of unsigned binary number 1101.011n Unsigned: 104
(2) – 10-3(2) - 1101.011(2) =
1111.111 – 1101.011 = 0010.100n Signed :(負數) 10010.100
11
61
2.8 addition and subtraction with r’s-complements
n Assume that N1 and N2 are unsigned numbers in base r (they are both positive)
n Find N1 – N2n N2’ 代表 r’s-補 of N2n N1 – N2 = N1 + N2’
62
Example 2.24
n N1 = 532, N2 = 146,find N1 – N2n The 10’s-complement of 146 is N2’ = 854n N1 – N2 = N1 + N2’= 532 + 854 = 1 386,
the carry 1 is ignored
n conventional addition of complementn N1 = 532 N1 = 532n - N2 = - 146 N2’= 854n N1 – N2 = 386 N1 + N2’= 1 386
63
Example 2.25
n N1 = 532, N2 = 146,find N2 – N1n The 10’s-complement of 532 is N1’ = 468n N2 – N1 = N2 + N1’= 146 + 468 = 614,
n conventional addition of complementn N2 = 146 N2 = 146n - N1 = - 532 N1’= 468n N2 – N1 = - 386 N2 + N1’= 614
64
Example 2.26n N1 = 11101.11, N2 = 01011.10,find
N1 – N2n The 2’s-complement of N2 is N2’= 10100.10n N1 – N2 = N1 + N2’= 11101.11 + 01011.10
= 1 10010.01, the carry 1 is ignored
n conventional addition of complementn N1 = 11101.11 N1 = 11101.11n -N2 = -01011.10 N2’= 10100.10n N1-N2 = 10010.01 N1+N2’=1 10010.01
65
Example 2.27n N1 = 11101.11, N2 = 01011.10,find
N2 – N1n The 2’s-complement of N1 is N1’= 00010.01n N2 – N1 = N2 + N1’= 01011.10 + 00010.01
= 01101.11,
n conventional addition of complementn N2 = 01011.10 N2 = 01011.10n - N1 =- 11101.11 N1’= 00010.01n N2-N1 =- 10010.01 N2+N1’= 01101.11
66
Conclusion
n N1 + N2’ = N1 + 10n – N2 = 10n + (N1 –N2)
n If N1 - N2 >= 0 , 1會出現在nth-order digit position,因為10n,代表最後會有一個carry進位,必須忽略.
n If N1 - N2 < 0 , 此時並無carry,代表結果正好是(N1 – N2)的補數
12
67
2.8.1 Signed addition and subtraction
n Signed number digit 被當作另一個 digit附加在原數前n 若最大digit加法產生的進位,會加入sign digit,
而sign digit 產生的進位一樣被捨去n 若運算結果造成sign digit出現1,表示數字部
分是一個補數
68
Example 2.28n Signed N1 = 0856.7, N2 = 0275.3,find N1 –
N2n The signed 10’s-complement of 0275.3 is N2’=
1724.7n N1 – N2 = N1 + N2’= 0856.7 + 1724.7 = 1 0581.4,
the carry 1 is ignored
n conventional addition of complementn N1 = 856.7 N1 = 0856.7 n - N2 = - 275.3 N2’= 1724.7 n N1 – N2 = 581.4 N1 + N2’= 1 0581.4
69
Example 2.29n Signed N1 = 0856.7, N2 = 0275.3,find N2 –
N1n The signed 10’s-complement of 0856.7 is N1’=
1143.3n N2 – N1 = N2 + N1’= 0275.3 + 1143.3 = 1418.6
n conventional addition of complementn N2 = 275.3 N2 = 0275.3 n - N1 = - 856.7 N1’= 1143.3n N2 – N1 = - 581.6 N2 + N1’= 1418.6
418.6是581.6的補數
70
Example 2.30n N1 = 011011.01, N2 = 010110.10,find N1 –
N2n The 2’s-complement of N2 is N2’= 101001.10n N1 – N2 = N1 + N2’= 011011.01 + 101001.10 = 1
000100.11,
n conventional addition of complementn N1 = 11011.01 N1 = 011011.01 n - N2 =- 10110.10 N2’= 101001.10 n N1-N2 = 00100.11 N1+N2’= 1 000100.11
71
Example 2.31n N1 = 011011.01, N2 = 010110.10,find N2 –
N1n The 2’s-complement of N1 is N1’= 100100.11n N2 – N1 = N2 + N1’= 010110.10 + 100100.11 =
111011.01,
n conventional addition of complementn N2 = 10110.10 N2 = 010110.10 n - N1 =- 11011.01 N1’= 100100.11n N2-N1 =- 00100.11 N2+N1’= 111011.01
72
Example 2.32
n N1 = 011011.01, N2 = 010110.10,find N2 + N1
n conventional addition of complementn N1 = 011011.01 n N2 = 010110.10n N1+N2’= 110001.11
2 正數的和竟是負數
overflow
13
73
2.8.1 overflow
n 只有n個digit來容納數字,若加/減法 處理完後需要n+1個digit來裝數字,就發生overflow
n 2種狀況會發生overflow :n 有carry進入 sign digit,但是sign digit卻無
carry 發生n 無carry進入 sign digit,但是sign digit卻有
carry 發生
74
Overflow in unsigned number
n When the result of an arithmetic operation exceeds the standard word size n, overflow occurs
n N-bit unsigned numbers overflowsn When output carry bit cn-1 = 1.
n X = 1110 1011 (235)10. n Y = 0010 1010 (42)10.
n Z = X + Y = 1110 1011 + 0010 1000 = 0001 0101 = (21)10.
n Sum = cn-1Z = c7Z = 1 0001 0101
75
Overflow in signed numbers
n Overflow is indicated by a flag bit v in CPU status registersn v = x’n-1y’n-1cn-2 + xn-1yn-1c’n-2 .n We can never have overflow on adding a
positive to a negative numbern 加2正數才會overflow
n 當2正數 (sign-bit = 0) 的 cn-2 = 1(2個很大正數才會造成 ), 表示 cn-2 跑到sign-bit 處
n 加2負數才會overflown 當2負數 (sign-bit = 1) 的 cn-2 = 0((2個很大負數
才會造成 ), 表示 cn-2 無法進為讓結果的sign-bit 變為1
n v = cn-1 xor cn-2 .76
2.9 addition and subtraction with (r-1)’s-complements
n 差別在於最後的carry進位處理方式:n 若end carry產生,則加入sum(和)的 least-
significant-digit: end-around carry
77
Example 2.33n unsigned decimal N1 = 85.2, N2 = 32.5,
find N1 – N2n The 9’s-complement of 32.5 is N2’ = 67.4n conventional addition of complementn N1 = 85.2 N1 = 85.2 n - N2 =- 32.5 N2’= 67.4 n N1 - N2 = 52.7 N1 + N2’= 1 52.6n + 1 n 52.7 = differenceEnd-around carry
78
Example 2.34
n unsigned decimal N1 = 85.2, N2 = 32.5,find N2 – N1n The signed 9’s-complement of 85.2 is N1’ =
14.7n conventional addition of complementn N2 = 32.5 N2 = 32.5 n - N1 = -85.2 N1’= 14.7n N2 - N1 = -52.7 N2 + N1’= 47.2
Difference in 9’s-complement form
14
79
Example 2.35
n N1 = 110.1, N2 = 011.0,find N1 – N2n The 1’s-complement of N2 is N2’= 100.1n conventional addition of complementn N1 = 110.1 N1 = 110.1 n - N2 =- 011.0 N2’= 100.1 n N1-N2 = 011.1 N1+N2’= 1 011.0n + 1n 011.1
Difference in 1’s-complement form
80
Example 2.36
n N1 = 110.1, N2 = 011.0,find N2 – N1n The 1’s-complement of N1 is N1’= 001.0n conventional addition of complementn N2 = 011.0 N2 = 011.0 n - N1 =- 110.1 N1’= 001.0n N2-N1 =- 011.1 N2+N1’= 100.0
Difference in 1’s-complement form
81
Signed addition and subtraction
n 同unsigned number
82
Example 2.37n Signed N1 = 054.2, N2 = 032.8,find
N1 – N2n The signed 9’s-complement of N2 is N2’ =
167.1n conventional addition of complementn N1 = 54.2 N1 = 054.2 n - N2 = - 32.8 N2’= 167.1 n N1 – N2 = 21.4 N1 + N2’= 1 021.3n + 1n 021.4
83
Example 2.38
n Signed N1 = 054.2, N2 = 032.8,find N2 – N1n The signed 9’s-complement of 054.2 is N1’ =
145.7n conventional addition of complementn N2 = 32.8 N2 = 032.8 n - N1 = - 54.2 N1’= 145.7n N2 – N1 = - 21.4 N2 + N1’= 178.5
84
Example 2.39
n N1 = 0110.101, N2 = 0010.110,find N1 – N2n conventional addition of complementn N1 = 110.101 N1 = 0110.101 n - N2 =- 010.110 N2’= 1101.001 n N1-N2 = 011.111 N1+N2’=1 0011.110n + 1n 0011.111
15
85
Example 2.40
n N1 = 0110.101, N2 = 0010.110,find N2 – N1n conventional addition of complementn N2 = 110.101 N2 = 0110.101 n - N1 =- 010.110 N1’= 1001.010n N2-N1 =- 011.111 N2+N1’= 1100.000
86
2.10 codes
n 除了數字外,尚有letters of the alphabetn 需要將 decimal symbols, letters of the
alphabet, special symbol 用一個唯一的binary digit來代表,才能存入記憶體中,這些binary digit稱做 code group
87
2.10.1 decimal codes
n BCD :n Called Binary Coded Decimal or decimal codesn 因有10不同的數字符號(0~9) ,故用4 bitsn 以4個位元為一組,表示十進位的值。故共有6
種變化未使用(1010~1111)n 最常用是 8421 code (weighted code)n N = b3b2b1b0
n = b3*w3 + b2*w2 + b1*w1 + b0*w0 .n 8 4 2 1
88
Table 2.7 weighted decimal codesn Decimal 8421 2421 5421 7536 5043210n 0 0000 0000 0000 0000 0100001n 1 0001 0001 0001 1001 0100010n 2 0010 0010 0010 0111 0100100n 3 0011 0011 0011 0010 0101000n 4 0100 0100 0100 1011 0110000n 5 0101 1011 1000 0100 1000001n 6 0110 1100 1001 1101 1000010n 7 0111 1101 1010 1000 1000100
89
Table 2.7 weighted decimal codesn Decimal 8421 2421 5421 7536 5043210n 8 1000 1110 1011 0110 1001000n 9 1001 1111 1100 1111 1010000
n 2421 code 具備n Self-complementingn 9: 1111 ó 0: 0000; 8: 1110 ó 1: 0001;
n 7536’ code具備n Self-complementingn 9: 1111 ó 0: 0000; 8: 0110 ó 1: 1001;
90
Table 2.7 weighted decimal codesn Biquinary 5043210 具備
n Error-detecting property
n Called Bi-quinary n 每一碼必定只有 2 個 bits 為 1 => bi-n 剩下 5 個 bits 故稱 quinary n 上述 2 項 合稱 bi-quinary
16
91
Table 2.8 nonweighted decimal codes
n Decimal digit Excess-3 code 2-out-of-5 coden 0 0011 11000 n 1 0100 00011n 2 0101 00101n 3 0110 00110n 4 0111 01001n 5 1000 01010n 6 1001 01100n 7 1010 10001
92
Table 2.8 nonweighted decimal codes
n Decimal digit Excess-3 code 2-out-of-5 coden 8 1011 10010 n 9 1100 10100
n Excess-3 code 具備n Self-complementing 能力;n 9: 1100 ó 0: 0011; 8: 1011 ó 1: 0100;
n Out-of-5 code 具備 error-detecting property
93
BCDIC
n 於BCD前方加上2個位元,共有6位元所可以表示的符號共有64個
94
EBCD
n 使用6個位元將字元編碼n 所表示的符號共有26 = 64種符號n 原是配合IBM公司打字機而開發,便於資訊傳
遞
95
EBCDIC
n 為IBM公司所發展n 所表示的符號有26個n IBM與FACOM電腦一般採用此碼,為常用的通
訊碼
96
Figure 2.3 U.S. Postal Service bar code
n Corresponding to the ZIP code 14263-1045n Frame bar used to align the scanner
17
97
2.10.2 unit-distance codes
n 類比的量 => digital representationn Gray code 就是這個例子n 相鄰 2 個數碼間只有 1 個 bit 變化n 應用例如下圖
98
Figure 2.4 Angular position encoders
n 透明. 遮光. 讀到值為 0011 msb lsb
順時鐘
99
Figure 2.5 Angular position encoders with misaligned photo sensing devices
n 當由 sector 3 -> 4 時, 會讀成 0111而非 0100n 若改成gray code, 可讀到正確的值 0110
100
THE END
top related