Escolar Documentos
Profissional Documentos
Cultura Documentos
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
9 10
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
15 16
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
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
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
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
33 34
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
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
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
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
57 58
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
= 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
12
Overflow in unsigned number
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
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
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;
BCDIC EBCD
n 於BCD前方加上2個位元,共有6位元所可以表 n 使用6個位元將字元編碼
示的符號共有64個 n 所表示的符號共有26 = 64種符號
n 原是配合IBM公司打字機而開發,便於資訊傳
遞
93 94
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
99 100
17