第 3 章 binary math and signed representations

34
Computer Organization and Design Fundamental 書書書書David Tarnoff 書書書書書書 書書書 3 第 Binary Math and Signed Representations

Upload: liana

Post on 05-Jan-2016

61 views

Category:

Documents


1 download

DESCRIPTION

第 3 章 Binary Math and Signed Representations. Computer Organization and Design Fundamental 書籍 作者: David Tarnoff 投影片製作者:陳鍾誠. 3.1 Binary Addition. 一位元加法 ( 半加器 ). 一位元加法 ( 全加器 ). 兩個二進位數相加. 3.2 Binary Subtraction. 一位元減法. 借位. 多位元減法. 3.3 Binary Complements ( 二補數 ). 1 補數 該數與其 1 補數相加 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: 第   3  章  Binary Math and Signed Representations

Computer Organization and Design Fundamental

書籍作者: David Tarnoff

投影片製作者:陳鍾誠

第 3 章 Binary Math and Signed

Representations

Page 2: 第   3  章  Binary Math and Signed Representations

3.1 Binary Addition

Page 3: 第   3  章  Binary Math and Signed Representations

一位元加法 ( 半加器 )

Page 4: 第   3  章  Binary Math and Signed Representations

一位元加法 ( 全加器 )

Page 5: 第   3  章  Binary Math and Signed Representations

兩個二進位數相加

Page 6: 第   3  章  Binary Math and Signed Representations

3.2 Binary Subtraction

Page 7: 第   3  章  Binary Math and Signed Representations

一位元減法

借位

Page 8: 第   3  章  Binary Math and Signed Representations

多位元減法

Page 9: 第   3  章  Binary Math and Signed Representations

3.3 Binary Complements (二補數 )1 補數

該數與其 1 補數相加

再加上 1

Page 10: 第   3  章  Binary Math and Signed Representations

二補數的秘密

Page 11: 第   3  章  Binary Math and Signed Representations

二補數加減法的例子88 與 10 的二進位與二補數

88-10 的二補數減法過程

Page 12: 第   3  章  Binary Math and Signed Representations

計算 2 補數的技巧

Page 13: 第   3  章  Binary Math and Signed Representations

2 補數的補數In decimal, the negative of 5 is -5. If we

take the negative a second time, we return to the original value, e.g., the egative of -5 is 5. Is the same true for taking the 2's complement of a 2's complement of a binary number?

Page 14: 第   3  章  Binary Math and Signed Representations

3.3.3 Most Significant Bit as a Sign IndicatorA binary value with a 0 in the MSB position

is considered positive and a binary value with a 1 in the MSB position is considered negative

Page 15: 第   3  章  Binary Math and Signed Representations

3.3.4 Signed Magnitude ( 正負號位元表示法 )

Page 16: 第   3  章  Binary Math and Signed Representations

3.3.5 MSB and Number of BitsSince the MSB is necessary to indicate the

sign of a binary value, it is vital that we know how many bits a particular number is being represented with so we know exactly where the MSB is.

以下位元串到底代表甚麼數字呢?

Page 17: 第   3  章  Binary Math and Signed Representations

3.3.6 Issues Surrounding the Conversion of Binary Numbers

2 補數正數轉為十進位

2 補數負數轉為十進位

Page 18: 第   3  章  Binary Math and Signed Representations

將 2 補數轉為 10 進位的流程圖

Page 19: 第   3  章  Binary Math and Signed Representations

最大最小值2 補數

正負號位元表示法

Page 20: 第   3  章  Binary Math and Signed Representations

數字系統的比較

Page 21: 第   3  章  Binary Math and Signed Representations

3.4 Floating Point Binary ( 浮點數的二進位表示法 )

Page 22: 第   3  章  Binary Math and Signed Representations

指數10n

2n

Page 23: 第   3  章  Binary Math and Signed Representations

「浮」點的意義

Page 24: 第   3  章  Binary Math and Signed Representations

浮點數的二進位編碼方式

Page 25: 第   3  章  Binary Math and Signed Representations

符點數解碼請問下列 32 位元浮點數代表何值

11010110101101101011000000000000

Page 26: 第   3  章  Binary Math and Signed Representations

符點數編碼請將下列二進位數編為浮點格式

0.000000110110100101

步驟 1:

步驟 2:

步驟 3:

Page 27: 第   3  章  Binary Math and Signed Representations

3.5 Hexadecimal Addition (16 進位加法 )

Page 28: 第   3  章  Binary Math and Signed Representations

16 進位加法範例請計算 3DA32 加上 4292F 的結果

Page 29: 第   3  章  Binary Math and Signed Representations

3.7 Multiplication and Division by Powers of Two

Page 30: 第   3  章  Binary Math and Signed Representations

用移位代替乘法Since a shift operation is significantly faster

than a multiply or divide operation, compilers will always substitute a shift operation when a program calls for a multiply or divide by a power of two.

但在右移時必需注意 MSB 的填入值

Page 31: 第   3  章  Binary Math and Signed Representations

用移位代替乘法 (C 語言版 )乘以 8

除以 16

Page 32: 第   3  章  Binary Math and Signed Representations

3.8 Easy Decimal to Binary Conversion Trick將 15610 轉為二進位

所以 15610 的 2 進位為 10011100

Page 33: 第   3  章  Binary Math and Signed Representations

3.9 Arithmetic Overflow (溢位 )20010 = 1 1 0 0 1 0 0 0

17510 = 1 0 1 0 1 1 1 1

20010 + 17510

溢位

Page 34: 第   3  章  Binary Math and Signed Representations

溢位範例 2