Você está na página 1de 17

PowerPoint Slides 2.

1 positional number systems


to accompany

Digital Principles and Design


Donald D. Givone n 872.64 = 800 + 70 + 2 + 0.6 + 0.04
n =8*102 + 7*101 + 2*100 + 6*10-1 +
4*10-2
Chapter 2 n Radix-weighted positional number system
Number Systems, Ar ithmetic, or called positional number system
and Codes n 表達一個 number 的方法
n 有一組有限符號的集合 called digits
n 每一個 digit 都是 nonnegative integer
1 2

2.1 Table 2.1

n N = dn-1dn-2… d1d0. d-1… d-m n Base Number system Digit symbols


n = dn-1*rn-1 + dn-2*rn-2 + … d1*r1 + d0*r0 + d- n 2 Binary 0,1
3 Ternary 0,1,2
1*r + … d-m*r
-1 -m ,0<= d <=(r-1) n
i
n r is the base of number system n 4 Quaternary 0,1,2,3
n n是N的整數部分 digits 的個數 n 5 Quinary 0,1,2,3,4
n m是N的小數部分 digits 的個數 n 8 Octal 0,1,2,3,4,5,6,7
n order是每一個 digit 的 power of base n 10 Decimal 0,1,2,3,4,5,6,7,8,9
n n=0 – 0th-order digit n 12 Duodecimal 0,1,2,3,4,5,6,7,8,9,A,B
n n=1 – 1th-order digit… n 16 Hexadecimal 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

3 4

Table 2.2
2.3 basic arithmetic operations
n Decimal Binary Ternary Octal Hexadecimal
n 0 0 0 0 0 n Addition
n 1 1 1 1 1
n 2 10 2 2 2 n Subtraction
n 3 11 10 3 3 n Multiplication
n 4 100 11 4 4
n 5 101 12 5 5 n Division
n 6 110 20 6 6
n 7 111 21 7 7
n 8 1000 22 10 8
n 9 1001 100 11 9
n 10 1010 101 12 A
n 11 1011 102 13 B 5 6

1
2.3.1 addition Example 2.1
n 1(2) + 1 (2) = 10 (2) n Binary
n 11 = carries
n 11010= augend
n + 11001= addend
n ============
n 110011= sum

7 8

Example 2.1 Example 2.2


n Binary n Ternary
n 1 1 = carries n 11 = carries
n 11.01= augend n 1102= augend
n + 10.01= addend n + 1022= addend
n ============ n ============
n 101.10= sum n 2201= sum

9 10

Example 2.2 2.3.2 subtraction


n Ternary n The inverse operation of addition is
n 11 1 = carries subtraction
n 1201.2= augend
n + 1200.1= addend
n ============
n 10102.0= sum

11 12

2
Table 2.3 Table 2.3
n a + b (binary) a+b b=0 b=1 n a + b (ternary)
n 0 + 0= 0 a=0 0 1
0 + 1= 1 a=1 1 0 and
n
a + b b=0 b=1 b=2
1 + 0= 1 carry 1
n
a=0 0 1 2
n 1 + 1= 0 and carry 1 a=1 1 2 0 and
carry 1
a=2 2 0 and 1 and
carry 1 carry 1

13 14

Table 2.4 Table 2.4


n a - b (binary) n a - b (ternary)
n 0 - 0 = 0
n 0 - 1 = 1 and borrow 1 a - b b=0 b=1 b=2
1 - 0 = 1
a=0 0 2 and 1 and
n

n 1 - 1 = 0 a-b b=0 b=1 borrow 1 borrow 1


a=0 0 1 and a=1 1 0 2 and
borrow 1 borrow 1
a=1 1 0 a=2 2 1 0

15 16

Example 2.3 Example 2.3


n a – b (binary) n a – b (ternary)
n 10001 = minuend n 2102 = minuend
n - 1011 = subtrahend n -1021 = subtrahend
n ------------------------- n -------------------------
n 110 = difference n 1011 = difference

n 02001 ó 01201 ó 01121 n 2102 ó 2032


n 01121 n 2032 = minuend
n - 1011 n -1021 = subtrahend
n --------- n -------------------------
n 00110 n 1011 = difference
17 18

3
2.3.3 multiplication Example 2.5
n 10.11 = multiplicand
n * 1 01 = multiplier
n -------------------------------
n 10 11
n 000 0 Array of partial prodcts
n 1011
n ------------------------------
n 1101.11 = product
19 20

Table 2.5 Table 2.5


n a*b (binary) n a*b (ternary)
n 2 * 2 = 4 = 3 + 1 = 1 and carry 1

a * b b=0 b=1
a=0 0 0 a * b b=0 b=1 b=2
a=1 0 1 a=0 0 0 0
a=1 0 1 2
a=2 0 2 1 and carry 1

21 22

2.3.4 division Example 2.7


n The process consists of multiplications and n Ternary
subtractions n 102 = quotient
n Divisor = 12 2010 = dividend
n -12
n 11
n -00
n 110
n -101 ó -24 ó -31 ó -101
n 2 = remainder
23 24

4
2.4 polynomial method of
Methods of number conversion number conversion
n Two basic procedures for converting n Base-r1 所表示的number system:
numbers in one number system into n N(r1) = (dn-1dn-2… d1d0. d-1… d-m)(r1),0<= di
another number system <=(r1-1)
n Polynomial method n N(r1) = dn-1(r1)*r1n-1(r1) + dn-2(r1)*r1n-2(r1) +..+ d-
m(r1)*r1 (r1) .
-m
n 將 base-r 所表達的 number => decimal number
system 較好用 n = dn-1(r1)*10n-1(r1) + dn-2(r1)*10n-2(r1) + d-m(r1)*10-
(r1) .
m
n Iterative method
n 將 decimal number system => base-r 所表達的 n N(r2) = dn-1(r2)*r1n-1(r2) + dn-2(r2)*r1n-2(r2) +..+ d-
number 較好用,但是整數與小數部分需要分開處
m(r2)*r1 (r2) .
-m

n r1(r2) 為 r1(r1) 轉成以 base-r2 的表示法,d 亦同
25 26

Example Example 2.9


n 1101(2) = n Binary => decimal
n 1(2)*103(2)+1(2)*102(2)+0(2)*101(2)+1(2)*100(2) n 101.011(2) = 1(2)*102(2) + 0(2)*101(2) +
n 1(10)*23(10)+1(10)*22(10)+0(10)*21(10)+1(10)*20(10) 1(2)*100(2) + 0(2)*10-1(2) + 1(2)*10-2(2) +
n =8+4+0+1 1(2)*10-3(2).
n = 13(10) . 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.125
n = 5.375(10) .
27 28

Example 2.10 Example 2.11


n Ternary => decimal n Decimal => binary
n 201.1(3) = 2(3)*102(3) + 0(3)*101(3) + n 113.5(10) = 1(10)*102(10) + 1(10)*101(10) +
1(3)*100(3) + 1(3)*10-1(3) . 3(10)*100(10) + 5(10)*10-1(10) .
n = 2(10)*32(10) + 0(10)*31(10) + 1(10)*30(10) + n = 1(2)*10102(2) + 1(2)*10101(2) +
1(10)*3-1(10) .
11(2)*10100(2) + 101(2)*1010-1(2) .
n = 18 + 0 + 0.333…
n = 1100100 + 1010 + 11 + 0.1
n = 19.33...
n = 1110001.1(2).
n 在轉換過程中,有可能需要較多的 digits
數目才能保證轉換後的 精確度 n 101(2)*1010-1(2) => ? 下頁說明
29 30

5
Example 2.11 Example 2.12
n 101(2)*1010-1(2) n Binary => ternary
n = 101/1010 n 11010(2) = 1(2)*104(2) + 1(2)*103(2) +
n 0.1 0(2)*102(2) + 1(2)*101(2) +0(2)*100(2) .
n 1010 101 0 n = 1(3)*24(3) + 1(3)*23(3) + 0(3)*22(3) +
n 101 0 1(3)*21(3) +0(3)*20(3) .
n 0 n = 121 + 22 + 0 + 2 + 0
n 1010 (2) => 1010*1010 = 1100100
2 n = 222(3).

31 32

2.5 iterative method of number


Example 2.13 conversion
n Ternary => binary n 將一數由 base-r1 => base-r2
n 2102(3) = 2(3)*103(3) + 1(3)*102(3) + n 將此數 除以 r2(r1) .
0(3)*101(3) + 2(3)*100(3) . n 所得餘數 就是單一 digit
n = 10(2)*113(2) + 1(2)*112(2) + 0(2)*111(2) + n 先得的是 LSB
10(2)*110(2) .
n = 110110 + 1001 + 0 + 10
n = 1000001(2).

33 34

Example 2.14 Example 2.15


n Decimal => binary n Decimal => hexadecimal
n 43(10) = ?(2) = n 213(10) = ?(16) =
43(10) / 2(10) = 21(10) .餘 1(10) = 1(2) =0th-order digit
213(10) / 16(10) = 13(10) .餘 5(10) = 5(16) =0th-
n
n
21(10) / 2(10) = 10(10) .餘 1(10) = 1(2) =1th-order digit
order digit
n

n 10(10) / 2(10) = 5(10) ..餘 0(10) = 0(2) =2th-order digit


n 13(10) / 16(10) = 0(10) .餘 13(10) = D(16) =1th-
n 5(10) / 2(10) = 2(10) ..餘 1(10) = 1(2) =3th-order digit
order digit
n 2(10) / 2(10) = 1(10) ..餘 0(10) = 0(2) =4th-order digit
n 1(10) / 2(10) = 0(10) ..餘 1(10) = 1(2) =5th-order digit n 213(10) = D5(16) . Stop

n 43(10) = 101011(2) . Stop

35 36

6
2.5.3 iterative method for
Example 2.16 converting fractions
n Binary => decimal n Conversion of fraction number N1(r1) into
n Conversion of 1001011(2) into its decimal its equivalent number N2(r2) .
equivalent by the iterative method n N1(r1)* r2(r1) = A.B(r1) ; A (r1) = A (r2) =Most
n 1001011(2)/1010(2) = 111(2) + 101(2); 101(2) = significant fraction digit
5(10) = 0th-order digit n B(r1)* r2(r1) = A’.B’(r1) ; A’(r1) = A’(r2) ;
n 111(2)/1010(2) = 0(2) + 111(2); 111(2) = 7(10).= n …
1th-order digit n B’(r1)* r2(r1) = C.0000(r1) ; C (r1) = C (r2) = Least
n 1001011(2) = 75(10) ; significant fraction digit Stop
n 有限digit轉換後,不見得仍是有限digit
37 38

Example 2.17 Example 2.18


n Conversion of 0.8125(10) into its equivalent n Conversion of 0.1011(2) into its equivalent
binary fraction decimal fraction
0.1011(2)* 1010(2) = 110.1110(2) ; 110 (2) = 6 (10)
0.8125(10)* 2(10) = 1.6250(10) ; 1 (10) = 1 (2)
n
n
=Most significant fraction digit
=Most significant fraction digit
n 0.1110(2)* 1010(2) = 1000.1100(2) ; 1000 (2) = 8 (10);
n 0.6250(10)* 2(10) = 1.2500(10) ; 1 (10) = 1 (2) ; n 0.1100(2)* 1010(2) = 111.1000(2) ; 111 (2) = 7 (10);
n 0.2500(10)* 2(10) = 0.5000(10) ; 0 (10) = 0 (2) ; n 0.1000(2)* 1010(2) = 101.0000(2) ; 101 (2) = 5 (10) =
0.5000(10)* 2(10) = 1.0000(10) ; 1 (10) = 1 (2) = Least significant fraction digit
n
Stop
Least significant fraction digit n 0.1011(2) = 0.6875(10) ;
Stop
n 0.8125(10) = 0.1101(2) ;
39 40

2.5.5 a final example Example 2.19


n 整數與小數要分開來轉換處理 n Conversion of 201.12(3) into its binary
n 中間用小數點連接 equivalent
n 201(3) / 2(3) = 100(3) .餘 1(3) = 1(2) =0th-order
digit
n 100(3) / 2(3) = 11(3) .餘 1(3) = 1(2) =1th-order
digit
n 11(3) / 2(3) = 2(3) .餘 0(3) = 0(2) =2th-order digit
n 2(3) / 2(3) = 1(10) .餘 0(3) = 0(2) =3th-order digit
n 1(3) / 2(3) = 0(3) .餘 1(3) = 1(2) =4th-order digit
n 201(3) = 10011(2) . Stop
41 42

7
Example 2.19 Example 2.19
n 0.12(3) * 2(3) = 1.01(3); 1(3) = 1(2) =Most
significant fraction digit repeating
n 0.01(3) * 2(3) = 0.02(3); 0(3) = 0(2)
n 201.12(3) = 10011.100011(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
43 44

2.6 special conversion procedures Base 2與 base 8轉換的證明


n 當1數在2種base 間轉換時,若此2種base n 若 N(2) = … d8d7… d1d0.d-1d-2d-3…
間有指數的關係時 n = … d8*28 + d7*27 + d6*26 + d5*25 + d4*24 +
n 8 = 23,16 = 24, d3*23 + d2*22 + d1*21 + d0*20 + d-1*2-1 + d-
2*2 + d-3*2 + …
-2 -3
n 從小數點起,向左及向右,數個bits為一組,
開始轉換。 n = … + (d8*22 + d7*21 + d6)*26 + (d5*22 +
n 11111101.0011(2) 分組成如: d4*21 + d3)*23 + (d2*22 + d1*21 + d0) *20 +
011111101.001100(2) ; (d-1*22 + d-2*21 + d-3) *2-3 + …
n 3 7 5 . 1 4(8) ; n = … + (d8*22 + d7*21 + d6)*82 + (d5*22 +
n 1 7 3 . 2 4(8) 可轉換成 d4*21 + d3)*81 + (d2*22 + d1*21 + d0) *80 +
(d-1*22 + d-2*21 + d-3) *8-1 + …
n 001111011.010100(2) ;
45 46

2.7 signed numbers and


2.6 special conversion procedures complements
n 001010110110.1110(2) n Signed-magnitude:
n =2 B 6 . E(16) ;
n 用1個符號代替(+) 、(-)號
n 3 A B . 2(16)
n Binary digit 0 代表(+)
n = 001110101011.0010(2) ;
n Binary digit 1 代表(-)

47 48

8
Graphical interpretation of sign-magnitude
numbers Graphical interpretation of complements
n 向右為正,向左為負 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 得一特殊值
49 50

Graphical interpretation of complements 2.7


n N1 + N2 得一特殊值 n 例如: 7 is the complement of 3
n 此特殊值就是 offset origin與 true origin之 n 7 + 3 = 10 ó base is 10
間的距離(displacement)

51 52

Complement Complement
n r’s-complement n rn – r-m 個單位.
or called radix complement or called true complement
r 是在自己數字系統中 base 數字的表示法
n
n
n offset origin 與 true origin之間的距離 = rn 單位.
n In decimal number called 10’s-補,for binary system n 例如: r = 10
called 2’s補
n n 是整數digit中最多的位數個數
n (r-1)’s-complement
n or called diminished-radix complement n 145,n = 3; 2974,n = 4; 365 - 29,n = 3;
n or called radix-minus-one complement n m 是小數部分digit中最多的位數個數
offset origin 與 true origin之間的距離 = rn – r-m 單位.
n
n 0.34,m = 2; 0.1 – 0.234,m = 3;
n In decimal number called 9’s-補,for binary system
called 1’s補
53 54

9
Table 2.6 representations of
Complement signed numbers
n r’s-complement of N = rn – N n Positive numbers
n (r-1)’s-complement of N = rn – r-m - N n All representations: 0N
n r 是在自己數字系統中 base 數字的表示法 n Negative numbers 0: 正數
1: 負數
n 例如: r = 10 n Sign-magnitude: 1N
n n 是整數digit中最多的位數個數 n Signed r’s-補: 1(rn – N)
n 145,n = 3; 2974,n = 4; 365 - 29,n = 3; n Signed (r-1)’s-補: 1(rn – r-m - N)

n m 是小數部分digit中最多的位數個數
n 0.34,m = 2; 0.1 – 0.234,m = 3;
55 56

Example 2.20 Example 2.21


n Find the 10’s-complement of the unsigned n Find the 9’s-complement of the unsigned
decimal number 123.45 decimal number 123.45
n Unsigned: 103 – 123.45 = 876.55 n Unsigned: 103 – 10-2 - 123.45 = 999.99 –
n Signed :(負數) 1876.55 123.45 = 876.54
n Signed :(負數) 1876.54

57 58

Example 2.22 Example 2.23


n Find the 2’s-complement of unsigned n Find the 1’s-complement of unsigned
binary number 1101.011 binary number 1101.011
n Unsigned: 104(2) – 1101.011(2) = 10000 – n Unsigned: 104(2) – 10-3(2) - 1101.011(2) =
1101.011 = 0010.101 1111.111 – 1101.011 = 0010.100
n Signed :(負數) 10010.101 n Signed :(負數) 10010.100

59 60

10
2.8 addition and subtraction with
r’s-complements Example 2.24
n Assume that N1 and N2 are unsigned n N1 = 532, N2 = 146,find N1 – N2
numbers in base r (they are both positive) n The 10’s-complement of 146 is N2’ = 854
n Find N1 – N2 n N1 – N2 = N1 + N2’ = 532 + 854 = 1 386,
n N2’ 代表 r’s-補 of N2 the carry 1 is ignored
n N1 – N2 = N1 + N2’
n conventional addition of complement
n N1 = 532 N1 = 532
n - N2 = - 146 N2’= 854
n N1 – N2 = 386 N1 + N2’= 1 386
61 62

Example 2.25 Example 2.26


n N1 = 532, N2 = 146,find N2 – N1 n N1 = 11101.11, N2 = 01011.10,find
n The 10’s-complement of 532 is N1’ = 468 N1 – N2
n N2 – N1 = N2 + N1’ = 146 + 468 = 614, n The 2’s-complement of N2 is N2’ = 10100.10
n N1 – N2 = N1 + N2’ = 11101.11 + 01011.10
= 1 10010.01, the carry 1 is ignored
n conventional addition of complement
n N2 = 146 N2 = 146 n conventional addition of complement
n - N1 = - 532 N1’= 468 n N1 = 11101.11 N1 = 11101.11
n N2 – N1 = - 386 N2 + N1’= 614 n -N2 = -01011.10 N2’= 10100.10
n N1-N2 = 10010.01 N1+N2’=1 10010.01
63 64

Example 2.27 Conclusion


n N1 = 11101.11, N2 = 01011.10,find n N1 + N2’ = N1 + 10n – N2 = 10n + (N1 –
N2 – N1 N2)
The 2’s-complement of N1 is N1’ = 00010.01
n
n If N1 - N2 >= 0 , 1會出現在nth-order
N2 – N1 = N2 + N1’ = 01011.10 + 00010.01
digit position,因為10n,代表最後會有一
n

= 01101.11,
個carry進位,必須忽略.
n conventional addition of complement n If N1 - N2 < 0 , 此時並無carry,代表結
n N2 = 01011.10 N2 = 01011.10 果正好是(N1 – N2)的補數
n - N1 =- 11101.11 N1’= 00010.01
n N2-N1 =- 10010.01 N2+N1’= 01101.11
65 66

11
2.8.1 Signed addition and
subtraction Example 2.28
n Signed number digit 被當作另一個 digit附 n Signed N1 = 0856.7, N2 = 0275.3,find N1 –
加在原數前 N2
n The signed 10’s-complement of 0275.3 is N2’ =
n 若最大digit加法產生的進位,會加入sign digit, 1724.7
而sign digit 產生的進位一樣被捨去 n N1 – N2 = N1 + N2’ = 0856.7 + 1724.7 = 1 0581.4,
the carry 1 is ignored
n 若運算結果造成sign digit出現1,表示數字部
分是一個補數
n conventional addition of complement
n N1 = 856.7 N1 = 0856.7
n - N2 = - 275.3 N2’= 1724.7
n N1 – N2 = 581.4 N1 + N2’= 1 0581.4

67 68

Example 2.29 Example 2.30


n Signed N1 = 0856.7, N2 = 0275.3,find N2 – n N1 = 011011.01, N2 = 010110.10,find N1 –
N1 N2
n The signed 10’s-complement of 0856.7 is N1’ = n The 2’s-complement of N2 is N2’ = 101001.10
1143.3 n N1 – N2 = N1 + N2’ = 011011.01 + 101001.10 = 1
n N2 – N1 = N2 + N1’ = 0275.3 + 1143.3 = 1418.6 000100.11,

n conventional addition of complement n conventional addition of complement


n N2 = 275.3 N2 = 0275.3 n N1 = 11011.01 N1 = 011011.01
418.6是581.6
n - N1 = - 856.7 N1’= 1143.3 的補數 n - N2 =- 10110.10 N2’= 101001.10
n N2 – N1 = - 581.6 N2 + N1’= 1418.6 n N1-N2 = 00100.11 N1+N2’= 1 000100.11
69 70

Example 2.31 Example 2.32


n N1 = 011011.01, N2 = 010110.10,find N2 – n N1 = 011011.01, N2 = 010110.10,find
N1 N2 + N1
n The 2’s-complement of N1 is N1’ = 100100.11
n N2 – N1 = N2 + N1’ = 010110.10 + 100100.11 =
111011.01, n conventional addition of complement
n N1 = 011011.01
n conventional addition of complement n N2 = 010110.10
N2 = 10110.10 N2 = 010110.10 overflow
n
n N1+N2’= 110001.11
n - N1 =- 11011.01 N1’= 100100.11
n N2-N1 =- 00100.11 N2+N1’= 111011.01 2 正數的和竟是負

71 72

12
Overflow in unsigned number

2.8.1 overflow n When the result of an arithmetic operation


n 只有n個digit來容納數字,若加/減法 處理 exceeds the standard word size n, overflow
完後需要n+1個digit來裝數字,就發生 occurs
overflow n N-bit unsigned numbers overflows
n 2種狀況會發生overflow : n When output carry bit cn-1 = 1.
n 有carry進入 sign digit,但是sign digit卻無 n X = 1110 1011 (235)10.
carry 發生 n Y = 0010 1010 (42)10.
n 無carry進入 sign digit,但是sign digit卻有 n Z = X + Y = 1110 1011 + 0010 1000 = 0001
carry 發生 0101 = (21)10.
n Sum = cn-1Z = c7Z = 1 0001 0101
73 74

Overflow in signed numbers


2.9 addition and subtraction with
n Overflow is indicated by a flag bit v in (r-1)’s-complements
CPU status registers
n v = x’n-1y’n-1cn-2 + xn-1yn-1c’n-2 . n 差別在於最後的carry進位處理方式:
n We can never have overflow on adding a n 若end carry產生,則加入sum(和)的 least-
positive to a negative number significant-digit: end-around carry
n 加2正數才會overflow
n 當2正數 (sign-bit = 0) 的 cn-2 = 1(2個很大正數才
會造成 ), 表示 cn-2 跑到sign-bit 處
n 加2負數才會overflow
n 當2負數 (sign-bit = 1) 的 cn-2 = 0((2個很大負數
才會造成 ), 表示 cn-2 無法進為讓結果的sign-bit
變為1
n v = cn-1 xor cn-2 .
75 76

Example 2.33 Example 2.34


n unsigned decimal N1 = 85.2, N2 = 32.5, n unsigned decimal N1 = 85.2, N2 = 32.5,
find N1 – N2 find N2 – N1
n The 9’s-complement of 32.5 is N2’ = 67.4 n The signed 9’s-complement of 85.2 is N1’ =
n conventional addition of complement 14.7
n N1 = 85.2 N1 = 85.2 n conventional addition of complement
- N2 =- 32.5 N2’= 67.4
N2 = 32.5 N2 = 32.5
n
n
n N1 - N2 = 52.7 N1 + N2’= 1 52.6
n - N1 = -85.2 N1’= 14.7
n + 1
End-around carry 52.7 = difference n N2 - N1 = -52.7 N2 + N1’= 47.2
n
Difference in 9’s-
77
complement form 78

13
Example 2.35 Example 2.36
n N1 = 110.1, N2 = 011.0,find N1 – N2 n N1 = 110.1, N2 = 011.0,find N2 – N1
n The 1’s-complement of N2 is N2’ = 100.1 n The 1’s-complement of N1 is N1’ = 001.0
n conventional addition of complement n conventional addition of complement
n N1 = 110.1 N1 = 110.1 n N2 = 011.0 N2 = 011.0
n - N2 =- 011.0 N2’= 100.1 n - N1 =- 110.1 N1’= 001.0
n N1-N2 = 011.1 N1+N2’= 1 011.0 n N2-N1 =- 011.1 N2+N1’= 100.0
n + 1 Difference in 1’s-
complement form
n 011.1
Difference in 1’s-
complement form
79 80

Signed addition and subtraction Example 2.37


n 同unsigned number n Signed N1 = 054.2, N2 = 032.8,find
N1 – N2
n The signed 9’s-complement of N2 is N2’ =
167.1
n conventional addition of complement
n N1 = 54.2 N1 = 054.2
n - N2 = - 32.8 N2’= 167.1
n N1 – N2 = 21.4 N1 + N2’= 1 021.3
n + 1
n 021.4
81 82

Example 2.38 Example 2.39


n Signed N1 = 054.2, N2 = 032.8,find n N1 = 0110.101, N2 = 0010.110,find
N2 – N1 N1 – N2
n The signed 9’s-complement of 054.2 is N1’ = n conventional addition of complement
145.7 n N1 = 110.101 N1 = 0110.101
n conventional addition of complement n - N2 =- 010.110 N2’= 1101.001
n N2 = 32.8 N2 = 032.8 n N1-N2 = 011.111 N1+N2’=1 0011.110
n - N1 = - 54.2 N1’= 145.7 n + 1
n N2 – N1 = - 21.4 N2 + N1’= 178.5 n 0011.111

83 84

14
Example 2.40 2.10 codes
n N1 = 0110.101, N2 = 0010.110,find n 除了數字外,尚有letters of the alphabet
N2 – N1 n 需要將 decimal symbols, letters of the
n conventional addition of complement alphabet, special symbol 用一個唯一的binary
n N2 = 110.101 N2 = 0110.101 digit來代表,才能存入記憶體中,這些binary
digit稱做 code group
n - N1 =- 010.110 N1’= 1001.010
n N2-N1 =- 011.111 N2+N1’= 1100.000

85 86

2.10.1 decimal codes Table 2.7 weighted decimal codes


n BCD : n Decimal 8421 2421 5421 7536 5043210
n Called Binary Coded Decimal or decimal codes n 0 0000 0000 0000 0000 0100001
n 因有10不同的數字符號(0~9) ,故用4 bits n 1 0001 0001 0001 1001 0100010
n 以4個位元為一組,表示十進位的值。故共有6 n 2 0010 0010 0010 0111 0100100
種變化未使用(1010~1111) n 3 0011 0011 0011 0010 0101000
n 最常用是 8421 code (weighted code) n 4 0100 0100 0100 1011 0110000
n N = b3b2b1b0 n 5 0101 1011 1000 0100 1000001
n = b3*w3 + b2*w2 + b1*w1 + b0*w0 . n 6 0110 1100 1001 1101 1000010
n 8 4 2 1 n 7 0111 1101 1010 1000 1000100
87 88

Table 2.7 weighted decimal codes Table 2.7 weighted decimal codes
n Decimal 8421 2421 5421 7536 5043210 n Biquinary 5043210 具備
n 8 1000 1110 1011 0110 1001000 n Error-detecting property
n 9 1001 1111 1100 1111 1010000 n Called Bi-quinary
n 每一碼必定只有 2 個 bits 為 1 => bi-
n 2421 code 具備 n 剩下 5 個 bits 故稱 quinary
n Self-complementing n 上述 2 項 合稱 bi-quinary
n 9: 1111 ó 0: 0000; 8: 1110 ó 1: 0001;
n 7536’ code具備
n Self-complementing
n 9: 1111 ó 0: 0000; 8: 0110 ó 1: 1001;
89 90

15
Table 2.8 nonweighted decimal Table 2.8 nonweighted decimal
codes codes
n Decimal digit Excess-3 code 2-out-of-5 code n Decimal digit Excess-3 code 2-out-of-5 code
n 0 0011 11000 n 8 1011 10010
n 1 0100 00011 n 9 1100 10100
n 2 0101 00101
n 3 0110 00110 n Excess-3 code 具備
n 4 0111 01001 n Self-complementing 能力;
n 5 1000 01010 n 9: 1100 ó 0: 0011; 8: 1011 ó 1: 0100;

n 6 1001 01100 n Out-of-5 code 具備 error-detecting property


n 7 1010 10001
91 92

BCDIC EBCD
n 於BCD前方加上2個位元,共有6位元所可以表 n 使用6個位元將字元編碼
示的符號共有64個 n 所表示的符號共有26 = 64種符號
n 原是配合IBM公司打字機而開發,便於資訊傳

93 94

EBCDIC Figure 2.3 U.S. Postal Service bar code


n 為IBM公司所發展 n Corresponding to the ZIP code 14263-1045
n 所表示的符號有26個 n Frame bar used to align the scanner
n IBM與FACOM電腦一般採用此碼,為常用的通
訊碼

95 96

16
2.10.2 unit-distance codes Figure 2.4 Angular position encoders

n 類比的量 => digital representation n 透明. 遮光. 讀到值為 0011 msb lsb
n Gray code 就是這個例子
n 相鄰 2 個數碼間只有 1 個 bit 變化
n 應用例如下圖

97
順時鐘98

Figure 2.5 Angular position encoders with


misaligned photo sensing devices THE END
n 當由 sector 3 -> 4 時, 會讀成 0111而非 0100
n 若改成gray code, 可讀到正確的值 0110

99 100

17

Você também pode gostar