Anda di halaman 1dari 55

第一章

數位系統與二進位碼
授課老師:黃俊堯
研究室:社4F14
E-mail: jyhuang@mail.ntpu.edu.tw

Digital Design, 4th Ed

章節
1-1 Digital Systems
1-2 Binary Numbers
1-3 Number Base Conversions
1-4 Octal and Hexadecimal Numbers
1-5 Complements
1-6 Signed Binary Numbers
1-7 Binary Codes
1-8 Binary Storage and Registers
1-9 Binary Logics
2008/2/23 第一章 數位系統與二進位碼 1
Digital Design, 4th Ed

1-1 Digital Systems


Components and Design Techniques for Digital Systems

Synchronous Digital Hardware Systems


l Synchronous: “Clocked” - all changes in the system are
controlled by a global clock (not asynchronous)
l Digital: All inputs/outputs and internal values (signals) take on
discrete values (not analog).
─ Example: sound waveform

─ A series of numbers is used to represent the waveform, rather than a


voltage or current, as in analog systems.
2008/2/23 第一章 數位系統與二進位碼 2

Digital Design, 4th Ed

Example Digital Systems


l Digital Computer

l Usually design to maximize performance. "Optimized for speed"

l Handheld Calculator
- Usually designed to minimize cost. “Optimized
for low cost”
- Of course, low cost comes at the expense of
speed.

2008/2/23 第一章 數位系統與二進位碼 3


Digital Design, 4th Ed

Example Digital Systems


l Digital Watch

Designed to minimize power.


Single battery must last for years.

l Low power operation comes at the expense of:


l lower speed
l higher cost

2008/2/23 第一章 數位系統與二進位碼 4

Digital Design, 4th Ed

Basic Design Tradeoffs

l You can improve on one at the expense of worsening one


or both of the others.
l These tradeoffs exist at every level in the system design -
every sub-piece and component.
l Design Specification -
l Functional Description.
l Performance, cost, power constraints.
l As a designer you must make the tradeoffs necessary to
achieve the function within the constraints.
2008/2/23 第一章 數位系統與二進位碼 5
Digital Design, 4th Ed

Design Representation

2008/2/23 第一章 數位系統與二進位碼 6

Digital Design, 4th Ed

Hierarchy in Designs
l Helps control complexity -
l by hiding details and reducing the total number of things to
handle at any time.
l Modulalizes the design -
l divide and conquer
l simplifies implementation and debugging
l Top-Down Design
l Starts at the top (root) and works down by successive refinement.
l Bottom-up Design
l Starts at the leaves & puts pieces together to build up the design.
l Which is better?
l In practice both are needed & used.
l Need top-down divide and conquer to handle the complexity.
l Need bottom-up because in a well designed system, the structure is
influence by what primitives are available.
2008/2/23 第一章 數位系統與二進位碼 7
Digital Design, 4th Ed

Digital Design
Given a functional description and performance, cost, & power constraints,
come up with an implementation using a set of primitives.
l How do we learn how to do this?
1. Learn about the primitives.
2. Learn about design representation.
3. Learn formal methods to optimally manipulate the representations.
4. Look at design examples.
5. Use trial and error - CAD tools and prototyping.
l Digital design is in some ways more an art than a science.
The creative spirit is critical in combining primitive elements &
other components in new ways to achieve a desired function.
l Unlike art, we have objective measures of a design:
performance cost power
2008/2/23 第一章 數位系統與二進位碼 8

Digital Design, 4th Ed

Signal
l An information variable represented by physical quantity
l For digital systems, the variable takes on discrete values
l Two level, or binary values are the most prevalent values
l Binary values are represented abstractly by:
l digits 0 and 1
l words (symbols) False (F) and True (T)
l words (symbols) Low (L) and High (H)
l and words On and Off.
l Binary values are represented by values or ranges of
values of physical quantities

2008/2/23 第一章 數位系統與二進位碼 9


Digital Design, 4th Ed

1-2 Binary Numbers


l Decimal number Base or radix

… a5a4a3a2a1.a−1a−2a−3… aj
Decimal point Power

L + 105 a5 + 104 a 4 + 103 a3 + 102 a 2 + 101 a1 + 100 a0 + 10−1 a −1 + 10 −2 a −2 + 10−3 a−3 + L

Example:
7,329 = 7 × 103 + 3 × 102 + 2 × 101 + 9 × 100

l General form of base-r system


an ⋅ r n + an −1 ⋅ r n−1 + L + a2 ⋅ r 2 + a1 ⋅ r1 + a 0 + a −1 ⋅ r −1 + a−2 ⋅ r −2 + L + a− m ⋅ r − m
Coefficient: aj = 0 to r − 1

2008/2/23 第一章 數位系統與二進位碼 10

Digital Design, 4th Ed

各種不同的數字系統
l 數字系統的不同在於每一個數本身基底的不同,基
底又稱為底數(base or radix)。基底的意義代表著
此數為幾進制的意思。
l 各種不同的數字系統要如何分辦呢?一般均會在數
碼的右下方標示一個較小的數字,以表示幾進位的
意思。
l 二進制常被使用於電腦內部的數值運算,十進制為
人類慣用的數字系統,十六進制則是人類與電腦溝
通時二進制的簡化表示法,即為了辨認的方便性而
將四個二進制數改寫成十六進制的一個元素。

2008/2/23 第一章 數位系統與二進位碼 11


Digital Design, 4th Ed

Binary Numbers
Example: Base-2 number
(11010.11)2 = (26.75)10
= 1 × 2 4 + 1 × 2 3 + 0 × 2 2 + 1 × 21 + 0 × 20 + 1 × 2 −1 + 1 × 2 −2
Example: Base-5 number
(4021.2)5
= 4 × 53 + 0 × 52 + 2 × 51 + 1 × 50 + 2 × 5−1 = (511.5)10

Example: Base-8 number


(127.4)8
= 1 × 83 + 2 × 82 + 1 × 81 + 7 × 80 + 4 × 8−1 = (87.5)10

Example: Base-16 number


(B65 F)16 = 11 × 163 + 6 × 16 2 + 5 × 161 + 15 × 160 = (46, 687)10
2008/2/23 第一章 數位系統與二進位碼 12

Digital Design, 4th Ed

Binary Numbers
Example: Base-2 number
(110101)2 = 32 + 16 + 4 + 1 = (53)10

Special Powers of 2
§ 210 (1024) is Kilo, denoted "K"

§ 220 (1,048,576) is Mega, denoted "M"

§ 230 (1,073, 741,824)is Giga, denoted "G"

Powers of two
Table 1.1
2008/2/23 第一章 數位系統與二進位碼 13
Digital Design, 4th Ed

Table 1.1

2008/2/23 第一章 數位系統與二進位碼 14

Digital Design, 4th Ed

二進制 ~ 十八進制間各種不同進制
的基本元素

2008/2/23 第一章 數位系統與二進位碼 15


Digital Design, 4th Ed

二進制的運算
l 二進制的加法運算
l 二進制的減法運算
l 二進制的乘法運算
l 二進制乘法運算也只是二進制加法運算的擴充而
已,只不過借助了一些移位暫存器來協助完成。
l 二進制的除法運算
l 電腦內部只有加法運算而已,若要完成除法運算就
必須利用二進制的減法運算(減法運算也是加法運
算搭配補數的應用),以及借助於右移位暫存器,
借助於左移位暫存器的應用,電腦也可以執行乘法
運算。
2008/2/23 第一章 數位系統與二進位碼 16

Digital Design, 4th Ed

常見的二進制的運算
l Single Bit Addition with Carry
l Multiple Bit Addition

l Single Bit Subtraction with Borrow

l Multiple Bit Subtraction

l Multiplication

l BCD Addition

2008/2/23 第一章 數位系統與二進位碼 17


Digital Design, 4th Ed

二進制的運算範例
l Addition l Subtraction
Augend: 101101 Minuend: 101101
Addend: +100111 Subtrahend: −100111

Sum: 1010100 Difference: 000110

l Multiplication
Multiplicand 1011
Multiplier × 101
Partial Products 1011
0000 -
1011 - -
Product 110111
2008/2/23 第一章 數位系統與二進位碼 18

Digital Design, 4th Ed

二進制的加法運算

電腦內部的主要運算其實只是加
法運算而己,其餘的減法、乘法、
除法…等種種運算都只是加法運算
的應用罷了。

2008/2/23 第一章 數位系統與二進位碼 19


Digital Design, 4th Ed

例題
l 試計算二進制數01011+10101=?
(A)100110 (B)100010 (C)100000 (D)101110

2008/2/23 第一章 數位系統與二進位碼 20

Digital Design, 4th Ed

二進制的減法運算
l 其實在電腦中二進制的減法運算,只不過是
二進制加法運算的應用罷了。
l 例如我們可以將A-B改成A+(-B) 來運算,如此即
成為加法運算了,但有一點需特別留意的,即
A+B的B與A+(-B) 的(-B) 是必須加以區隔的,否
則電腦會將其視為是相同的。
l 因此我們必須將 -B改變成另一種表示方式,即
取補數的方式來與A做加法運算。

2008/2/23 第一章 數位系統與二進位碼 21


Digital Design, 4th Ed

人類運算與電腦運算比較:
人類運算方式: 電腦運算方式:
0 – 0= 0 0 – 0 = 0+(-0) = 0
0 – 1= -1 0 – 1 = 0+(-1) = -1
1 – 0= 1 1 – 0 = 1+(-0) = 1
1 – 1= 0 1 – 1 = 1+(-1) = 0

2008/2/23 第一章 數位系統與二進位碼 22

Digital Design, 4th Ed

例題:

2008/2/23 第一章 數位系統與二進位碼 23


Digital Design, 4th Ed

1-3 數字基底的轉換

Name Radix Digits


Binary 2 0,1
Octal 8 0,1,2,3,4,5,6,7
Decimal 10 0,1,2,3,4,5,6,7,8,9
Hexadecimal 16 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
§ The six letters (in addition to the 10 integers) in
hexadecimal represent: 10, 11, 12, 13, 14, and 15,
respectively.
2008/2/23 第一章 數位系統與二進位碼 24

Digital Design, 4th Ed

十進位整數的基底轉換
l 十進位整數N10部分轉換為以 r 為基底之數字
=> 利用除法
N n−1 n−2
1. r = a n r + a n −1r + .... + a 2 r 1
+ a1 = Q1 餘數 a0
Q
2. 1 = an r n −2 + an−1r n−3 + .... + a2 = Q2 餘數 a1
r
3. Q2 = an r n−3 + an−1r n−4 + .... + a3 = Q3 餘數 a2
r
……
直到商數為0為止‚而每次除法後所得的餘數即為以 r 為基底
數字的係數. Ü N = (a a .....a a a )
10 n n−1 2 1 0 r
n−1
= an r + an−1r
n
+ .... + a2 r 2 + a1r1 + a0 r 0
2008/2/23 第一章 數位系統與二進位碼 25
Digital Design, 4th Ed

數字基底的轉換範例
Example 1:十進數41轉換成二進數
整數商 餘數 係數
41/2 = 20 + 1/2 a0 = 1
20/2 = 10 + 0 a1 = 0
10/2 = 5 + 0 a2 = 0
5/2 = 2 + 1/2 a3 = 1
2/2 = 1 + 0 a4 = 0
1/2 = 0 + 1/2 a5 = 1

解答為 (41)10 = (a5a4 a3a2 a1a0 ) 2 = (101001) 2


2008/2/23 第一章 數位系統與二進位碼 26

Digital Design, 4th Ed

Number-Base Conversions
l The arithmetic process can be manipulated more
conveniently as follows:

2008/2/23 第一章 數位系統與二進位碼 27


Digital Design, 4th Ed

Number-Base Conversions
l Example 1.2
l Convert decimal 153 to octal. The required base r is 8.

l Example1.3
l Convert (0.6875)10 to binary.
l The process is continued until the fraction becomes 0 or
until the number of digits has sufficient accuracy.
2008/2/23 第一章 數位系統與二進位碼 28

Digital Design, 4th Ed

數字基底的轉換(十進數小數部分)
l 十進位小數部分轉換為以 r 為基底之數字

F10 = (0.a−1a−2 .....a−m ) r


= a−1r −1 + a−2 r −2 + .... + a−m r −m

利用乘法
rF = a−1 + a−2 r −1 + a−3r −2 + .... + a−m r −m+1 = a−1 + P1
rP1 = a−2 + a−3r −1 + a−4 r −2 + .... + a−m r −m+ 2 = a−2 + P2

2008/2/23 第一章 數位系統與二進位碼 29


Digital Design, 4th Ed

數字基底的轉換(十進數小數部分)

rP2 = a−3 + a−4 r −1 + a−5 r −2 + .... + a−m r − m+3 = a−3 + P3


……
直到沒有小數部份或所要求位元數為止,而乘積後
所得整數部分即為以 r 為基底數字的係數.

2008/2/23 第一章 數位系統與二進位碼 30

Digital Design, 4th Ed

數字基底的轉換範例

Example1.3 :轉換 (0.6875)10 為二進數


整數 小數 係數
0.6875x2= 1 + 0.3750 a−1 = 1
0.3750x2= 0 + 0.7500 a− 2 = 0
0.7500x2= 1 + 0.5000 a− 3 = 1
0.5000x2= 1 + 0.0000 a− 4 = 1

解答為 (0.6875)10 = (0.a−1a−2 a−3a−4 ) 2 = (0.1011) 2

2008/2/23 第一章 數位系統與二進位碼 31


Digital Design, 4th Ed

Number-Base Conversions
l Example1.4
l Convert (0.513)10 to octal.

l From Examples 1.1 and 1.3:


l (41.6875)10 = (101001.1011)2
l From Examples 1.2 and 1.4:
l (153.513)10 = (231.406517)8
2008/2/23 第一章 數位系統與二進位碼 32

Digital Design, 4th Ed

1-4 八進位及十六進位數字

2008/2/23 第一章 數位系統與二進位碼 33


Digital Design, 4th Ed

八進位及十六進位數字
l 二進數轉換成八進數
(10 110 001 101 011 . 111 100 000 110) 2 = (26153.7406)8
2 6 1 5 3 7 4 0 6

l 二進數轉換成十六進數

2008/2/23 第一章 數位系統與二進位碼 34

Digital Design, 4th Ed

八進位及十六進位數字
l 八進數或十六進數轉換成二進數
EX:

2008/2/23 第一章 數位系統與二進位碼 35


Digital Design, 4th Ed

不同數字基底之間的轉換

2008/2/23 第一章 數位系統與二進位碼 36

Digital Design, 4th Ed

1-5 補數(Complement)
l 補數有兩類型:r-1補數及 r 補數
l r-1補數,又稱為diminished radix complement
對於具有n個位元且基底為r的數字N,則N之 r-1
的補數定義為 (r n − 1) − N

EX:
54670010之9的補數為999999-546700=453299
01239810之9的補數為999999-012398=987601
01011012之1的補數為1010010
2008/2/23 第一章 數位系統與二進位碼 37
Digital Design, 4th Ed

r-1的補數
l r可以表示為任何進制的基底,因此, r-1的補
數就是基底本身減1的補數。
l 因為基底是r,所以基底本身減1的補數就稱為r-1的
補數。
l r代表本身是幾進制的意思,以十進制為例,r就是
10,r-1就是9。

2008/2/23 第一章 數位系統與二進位碼 38

Digital Design, 4th Ed

例題

2008/2/23 第一章 數位系統與二進位碼 39


Digital Design, 4th Ed

補數
l r 的補數,又稱為 radix complement
對於具有n個位元且基底為 r 的數字N,則N之 r 的補
數定義為
 0 , if N =0 
 n 
r − N , if N ≠0 
è [( ) ]
r n − N = r n −1 − N +1 (Adding 1 to the r-1’s complement)

EX: The 10's complement of 012398 is 987602


The 10's complement of 246700 is 753300
01239810之10的補數為987602
The 2's complement of 1101100 is 0010100
01101112之2的補數為1001001 The 2's complement of 0110111 is 1001001
2008/2/23 第一章 數位系統與二進位碼 40

Digital Design, 4th Ed

r 補數
l r可以表示為任何進制的基底,因此,r的補數就是
基底本身的補數。
l 因為基底是r,所以基底本身的補數就稱為r的補數。

2008/2/23 第一章 數位系統與二進位碼 41


Digital Design, 4th Ed

例題

2008/2/23 第一章 數位系統與二進位碼 42

Digital Design, 4th Ed

以補數做減法
l 兩個n位元且基底為 r 的無正負號 M-N 的減法:
1、將被減數M與減數N之 r 的補數相加。
也就是說 M + (r n − N ) = M − N + r n 。
2、若 M ≥ N,則總和會產生一個末進位r n ,則去掉末進
位 剩下的就是 M-N。
3、若 M < N,則總和不會產生末進位,結果等於r n– (N –
M) ,這個數字是 N –M 之 r 的補數。為了得到慣用的
答案形式,則將剛才加法所得的和再求其的補數並在前
面加上負號,即為答案。

2008/2/23 第一章 數位系統與二進位碼 43


Digital Design, 4th Ed

Example 1.5
EX:利用10的補數法求 72532 - 3250
M= 72532
N之10的補數= + 96750 (= 105 - 3250)
和= 169282
去掉末進位105 = -100000
答案= 69282

2008/2/23 第一章 數位系統與二進位碼 44

Digital Design, 4th Ed

Example 1.6
利用10的補數法求 03250 - 72532
M= 03250
N之10的補數= + 24768 (= 105 - 72532)
和= 30718
沒有末進位產生,所以要對計算結果執行補數運
算,因此,答案為-(30718之10的補數)
= -69282
è我們可以用進位來判斷是否要對總和作補數運算

2008/2/23 第一章 數位系統與二進位碼 45


Digital Design, 4th Ed

Example 1.7
l Given the two binary numbers X = 1010100 and Y =
1000011, perform the subtraction (a) X – Y and (b) Y − X
by using 2's complement.

There is no end carry.


Therefore, the answer is
Y – X = − (2's complement
of 1101111) = − 0010001.
2008/2/23 第一章 數位系統與二進位碼 46

Digital Design, 4th Ed

Example 1.8
l Subtraction of unsigned numbers can also be done by means of the (r −
1)'s complement. Remember that the (r − 1) 's complement is one less
then the r's complement.
l Repeat Example 1.7, but this time using 1's complement.

There is no end carry,


Therefore, the answer is
Y – X = − (1's complement
of 1101110) = − 0010001.
2008/2/23 第一章 數位系統與二進位碼 47
Digital Design, 4th Ed

1-6 二進位有符號的數字表示法
l To represent negative integers, we need a
notation for negative values.
l It is customary to represent the sign with a bit
placed in the leftmost position of the number.
l The convention is to make the sign bit 0 for
positive and 1 for negative
l Example:

2008/2/23 第一章 數位系統與二進位碼 48

Digital Design, 4th Ed

Example
l 有符號數字

l 無符號數字

2008/2/23 第一章 數位系統與二進位碼 49


Digital Design, 4th Ed

Signed Binary Numbers

♣ Table 3 lists all


possible four-bit
signed binary
numbers in the
three
representations.

2008/2/23 第一章 數位系統與二進位碼 50

Digital Design, 4th Ed

符號大小表示法
l 符號大小表示法是以二進制的形式來表示的,
因此凡是非二進制的數,都必須先將其轉換成
二進制後,才能用符號大小表示法來表示。
l 所謂的符號大小表示法,即是將所有的表示位
元之最左邊的一個位元規定為符號位元,若於
符號位元內填上“0”代表正數,填上“1”代表負
數。
l 對於符號大小表示法而言,正數與負數的表示
方法只在於符號位元的不同而已,其數值位元
是沒有任何差異的。
2008/2/23 第一章 數位系統與二進位碼 51
Digital Design, 4th Ed

Signed Binary Number


l Table 1-3(Page 14)

-1

-2
Two

-3

-4

2008/2/23 第一章 數位系統與二進位碼 52

Digital Design, 4th Ed

Arithmetic Addition
l The addition of two numbers in the signed-
magnitude system follows the rules of ordinary
arithmetic. If the signs are the same, we add the
two magnitudes and give the sum the common
sign. If the signs are different, we subtract the
smaller magnitude from the larger and give the
difference the sign if the larger magnitude.

2008/2/23 第一章 數位系統與二進位碼 53


Digital Design, 4th Ed

Arithmetic Addition (Example)


l The addition of two signed binary numbers with
negative numbers represented in signed-2's-
complement form is obtained from the addition of
the two numbers, including their sign bits.
l A carry out of the sign-bit position is discarded.

2008/2/23 第一章 數位系統與二進位碼 54

Digital Design, 4th Ed

Arithmetic Subtraction
l In 2’s-complement form:
l Take the 2’s complement of the subtrahend (including
the sign bit) and add it to the minuend (including sign
bit).
l A carry out of sign-bit position is discarded.
(± A) − (+ B ) = ( ± A) + (− B )
(± A) − (− B ) = (± A) + ( + B)
Example:

(− 6) − (− 13) (11111010 − 11110011)


(11111010 + 00001101)

00000111 (+ 7)
2008/2/23 第一章 數位系統與二進位碼 55
Digital Design, 4th Ed

1-7 常見之二進數碼
l BCD碼
l 葛雷碼
l 超3碼
l 2421加權碼
l 84-2-1加權碼
l ASCII字元碼

2008/2/23 第一章 數位系統與二進位碼 56

Digital Design, 4th Ed

二進制碼
l 所謂二進制碼即是由一長串的
二進制元素0與1所組合而成,
例如1011001111100101(2)即
是二進制碼,任何二進制碼的
數所代表的意義,即是指其所
代表十進制的數為何?
l 二進制碼上的每一個位元,均
有其固定的加權值,由右至左
每一個位元均有著兩倍的加權
值。

2008/2/23 第一章 數位系統與二進位碼 57


Digital Design, 4th Ed

例題:

2008/2/23 第一章 數位系統與二進位碼 58

Digital Design, 4th Ed

BCD碼

l 常久以來人類慣用十進制來做算術運算,但新
科技的電腦卻只能使用二進制來做算術運算,
因此為了讓電腦能夠協助人類做一些算術運
算,所以使用了BCD碼來作為人類與電腦之間
的一種溝通橋樑。
l 所謂BCD碼就是固定以四個位元(4 bit)的二進制
來表示十進制的一種數碼,因此BCD碼稱為“二
進制十進碼”。

2008/2/23 第一章 數位系統與二進位碼 59


Digital Design, 4th Ed

8421(BCD)碼與十進制的對照關係表

Table 1-4

2008/2/23 第一章 數位系統與二進位碼 60

Digital Design, 4th Ed

例題:

2008/2/23 第一章 數位系統與二進位碼 61


Digital Design, 4th Ed

BCD加法

4 0100 4 0100 8 1000


+5 +0101 +8 +1000 +9 +1001
9 1001 12 1100 17 10001
Add 6 +0110 +0110
BCD sum 00010010 00010111
Example:
Consider decimal 185 and its corresponding value in BCD
and binary:

2008/2/23 第一章 數位系統與二進位碼 62

Digital Design, 4th Ed

Binary Codes
Example:
l Consider the addition of 184 + 576 = 760 in BCD

l Decimal Arithmetic

2008/2/23 第一章 數位系統與二進位碼 63


Digital Design, 4th Ed

Other Decimal Codes

2008/2/23 第一章 數位系統與二進位碼 64

Digital Design, 4th Ed

84-2-1碼
l 由前面可以知道8421碼字面上的數字 8421是代
表四個加權值的意思。同樣地,84-2-1碼字面
上的數字 “84-2-1”必也是加權值。
l 兩者之間的差異只在於後面兩個加權值不同而
已,亦即一個為正值,而另一個為負值。由此
可知,84-2-1碼也與8421碼一樣均屬於四個位
元的二進制碼的特殊應用。

2008/2/23 第一章 數位系統與二進位碼 65


Digital Design, 4th Ed

84-2-1碼與十進制的對照關係表

2008/2/23 第一章 數位系統與二進位碼 66

Digital Design, 4th Ed

例題:

2008/2/23 第一章 數位系統與二進位碼 67


Digital Design, 4th Ed

2421碼

l 由前面可以知道8421碼字面上的數字 8421是代
表四個加權值的意思。同樣地,2421碼字面上
的數字 “2421”必也是加權值。
l 兩者之間的差異只在於最左邊的一個加權值不
同而已,亦即一個為8,而另一個為2。

2008/2/23 第一章 數位系統與二進位碼 68

Digital Design, 4th Ed

2421碼與十進制的對照關係表

2008/2/23 第一章 數位系統與二進位碼 69


Digital Design, 4th Ed

例題:

2008/2/23 第一章 數位系統與二進位碼 70

Digital Design, 4th Ed

加三碼(Excess-3 code)

l 加三碼必須是由BCD碼轉換而來,舉凡一切非
BCD碼者,均必須先行轉換成BCD碼後才能正
確轉換成加三碼。
l 我們只要將BCD碼加上0011即成加三碼。

2008/2/23 第一章 數位系統與二進位碼 71


Digital Design, 4th Ed

加三碼與BCD碼、十進制的對照表

2008/2/23 第一章 數位系統與二進位碼 72

Digital Design, 4th Ed

例題:

2008/2/23 第一章 數位系統與二進位碼 73


Digital Design, 4th Ed

格雷碼 (Gray code)

l 格雷碼是非加權碼的一種,因為它的每一個位
元均無固定的乘冪或加權值,因此無法拿來作
為算術運算之用。
l 格雷碼是由二進制碼轉換而來,因此欲轉換成
格雷碼時,必須先行轉換為二進制碼後才能轉
換成格雷碼。
l 格雷碼的優點是相鄰編碼之間只差一個位元,
其餘一樣。

2008/2/23 第一章 數位系統與二進位碼 74

Digital Design, 4th Ed

格雷碼與二進制碼的對照關係表

2008/2/23 第一章 數位系統與二進位碼 75


Digital Design, 4th Ed

例題:

2008/2/23 第一章 數位系統與二進位碼 76

Digital Design, 4th Ed

標準BCD碼
l 標準BCD碼的英文全名為BCD Interchange
Code,所以又稱為BCDIC碼或BCD交換碼。
l 標準BCD碼是BCD碼的擴展,比BCD碼多兩個
位元,以六個位元組成,即在BCD碼的前面加
兩個位元作為區域位元(Zone Bits),BCD碼
原來的四個位元則作為數字位元(Digital
Bits)。

2008/2/23 第一章 數位系統與二進位碼 77


Digital Design, 4th Ed

標準BCD碼格式

2008/2/23 第一章 數位系統與二進位碼 78

Digital Design, 4th Ed

標準BCD碼字符表

2008/2/23 第一章 數位系統與二進位碼 79


Digital Design, 4th Ed

例題:

2008/2/23 第一章 數位系統與二進位碼 80

Digital Design, 4th Ed

ASCII碼

l ASCII碼的英文全名是American Standard
Code for Information Interchange,中文稱為
美國標準資訊交換碼。
l 在當時美國國家標準局(American National
Standard Institute,簡稱ANSI)為了要讓各家
廠商所製造的電腦能有一致的文數字碼可以相
通,不會因為電腦廠牌不同而無法相互溝通,
因此制定了一套標準化的資訊交換碼,使得不
同的電腦都有共同的標準可依循。
2008/2/23 第一章 數位系統與二進位碼 81
Digital Design, 4th Ed

ASCII碼格式

2008/2/23 第一章 數位系統與二進位碼 82

Digital Design, 4th Ed

ASCII碼格式

2008/2/23 第一章 數位系統與二進位碼 83


Digital Design, 4th Ed

ASCII碼格式
l American Standard Code for Information
Interchange (Refer to Table 1.7)
l A popular code used to represent information sent
as character-based data.
l It uses 7-bits to represent:
l 94 Graphic printing characters.
l 34 Non-printing characters
l Some non-printing characters are used for text
format (e.g. BS = Backspace, CR = carriage return)
l Other non-printing characters are used for record
marking and flow control (e.g. STX and ETX start
and end text areas).
2008/2/23 第一章 數位系統與二進位碼 84

Digital Design, 4th Ed

ASCII Properties

l ASCII has some interesting properties:


l Digits 0 to 9 span Hexadecimal values 3016 to 3916.
l Upper case A-Z span 4116 to 5A16
l Lower case a-z span 6116 to 7A16
l Lower to upper case translation (and vice versa) occurs by
flipping bit 6.
l Delete (DEL) is all bits set, a carryover from when
punched paper tape was used to store messages.
l Punching all holes in a row erased a mistake!

2008/2/23 第一章 數位系統與二進位碼 85


Digital Design, 4th Ed

ASCII碼格式

2008/2/23 第一章 數位系統與二進位碼 86

Digital Design, 4th Ed

ASCII碼的字符表

2008/2/23 第一章 數位系統與二進位碼 87


Digital Design, 4th Ed

例題:

2008/2/23 第一章 數位系統與二進位碼 88

Digital Design, 4th Ed

EBCDIC碼

l EBCDIC碼的英文全名是Extended Binary
Coded Decimal Interchange Code,稱為擴展
的BCDIC碼,或稱擴展的BCD交換碼。
l EBCDIC碼是BCDIC碼的擴展,比BCDIC碼多
兩個位元,比BCD碼多四個位元,以八個位元
組成,即在BCD碼的前面加四個位元作為區域
位元(Zone Bits),BCD碼原來的四個位元則
作為數字位元(Digital Bits)。

2008/2/23 第一章 數位系統與二進位碼 89


Digital Design, 4th Ed

EBCDIC碼的格式

2008/2/23 第一章 數位系統與二進位碼 90

Digital Design, 4th Ed

EBCDIC碼的字符表

2008/2/23 第一章 數位系統與二進位碼 91


Digital Design, 4th Ed

例題:

2008/2/23 第一章 數位系統與二進位碼 92

Digital Design, 4th Ed

Error-Detecting Code
l 同位元碼(Parity code)不但可以用來檢查數字,也
可以用來檢查資料,是屬於資料檢查碼的一種。
l 其作法是在資料位元的前面或後面,加入一個位
元的0或1,使其成為偶數個1或奇數個1。
l Example
l Consider the following two characters and their even
and odd parity:

2008/2/23 第一章 數位系統與二進位碼 93


Digital Design, 4th Ed

Error-Detecting Code
l Redundancy (e.g. extra information), in the form
of extra bits, can be incorporated into binary code
words to detect and correct errors.
l A simple form of redundancy is parity, an extra bit
appended onto the code word to make the
number of 1’s odd or even. Parity can detect all
single-bit errors and some multiple-bit errors.
l A code word has even parity if the number of 1’s
in the code word is even.
l A code word has odd parity if the number of 1’s in
the code word is odd.
2008/2/23 第一章 數位系統與二進位碼 94

Digital Design, 4th Ed

同位元碼與3 bits的二進制碼對照表

2008/2/23 第一章 數位系統與二進位碼 95


Digital Design, 4th Ed

1-8 Binary Storage and Registers


l A binary cell is a device that possesses two
stable states
l It is capable of storing one bit of information.
l The information stored in a cell is 1 when it is in one
stable state and 0 when in the other stable state.
l Examples: flip-flop circuits, ferrite cores, capacitor

2008/2/23 第一章 數位系統與二進位碼 96

Digital Design, 4th Ed

Binary Storage and Registers


l A register is a group of binary cells.
l A register with n cells can store any discrete quantity
of information that contains n bits.
n cells 2n possible states
l A register transfer operation is a basic operation
in digital systems.
l Manipulation of binary variables is done by
means of digital logic circuits.

2008/2/23 第一章 數位系統與二進位碼 97


Digital Design, 4th Ed

Transfer of Information with


Registers

2008/2/23 第一章 數位系統與二進位碼 98

Digital Design, 4th Ed

範例
l The other major
component of a digital
system
l circuit elements to
manipulate individual bits of
information

2008/2/23 第一章 數位系統與二進位碼 99


Digital Design, 4th Ed

1-9 二進位邏輯
l 三個基本的邏輯運算
AND 、 OR 、NOT 。
1、AND: x ⋅ y = z ,z=1 充要條件是x=1且y=1;
否則z=0。
2、OR: x + y = z ,若 x=1或y=1或同時 x=1且y=1
則 z=1;如果同時 x=0且y=0 則 z=0。
3、NOT: x′ = z 或 x = z ,如果 x=0 則 z=1;
如果 x=1 則 z=0。
2008/2/23 第一章 數位系統與二進位碼 100

Digital Design, 4th Ed

二進位邏輯真值表
l 真值表

AND OR NOT
x y x⋅ y x y x+ y x x′
0 0 0 0 0 0 0 1
0 1 0 0 1 1 1 0
1 0 0 1 0 1
1 1 1 1 1 1

2008/2/23 第一章 數位系統與二進位碼 101


Digital Design, 4th Ed

二進位邏輯
l Example of binary
signals

2008/2/23 第一章 數位系統與二進位碼 102

Digital Design, 4th Ed

Signal Examples Over Time

Time
Continuous in
value & time
Analog

Digital Discrete in
value &
Asynchronous continuous in
time

Synchronous Discrete in
value & time

2008/2/23 第一章 數位系統與二進位碼 103


Digital Design, 4th Ed

Signal Example – Physical


Quantity: Voltage

OUTPUT INPUT
5.0
HIGH HIGH
4.0
3.0
Threshold
2.0 Region
1.0
LOW LOW
0.0
Volts
2008/2/23 第一章 數位系統與二進位碼 104

Digital Design, 4th Ed

邏輯閘
l Graphic Symbols and Input-Output Signals
for Logic gates:

2008/2/23 第一章 數位系統與二進位碼 105


Digital Design, 4th Ed

Input Signals for Gates

2008/2/23 第一章 數位系統與二進位碼 106

Digital Design, 4th Ed

Multiple Inputs
l Graphic Symbols and Input-Output Signals
for Logic gates

2008/2/23 第一章 數位系統與二進位碼 107


Digital Design, 4th Ed

Question?
l Exercises

l 繳交日期:

2008/2/23 第一章 數位系統與二進位碼 108

Anda mungkin juga menyukai