350 likes | 556 Views
第 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 補數相加
E N D
第 3 章 Binary Math and Signed Representations Computer Organization and Design Fundamental 書籍作者:David Tarnoff 投影片製作者:陳鍾誠
一位元減法 借位
3.3 Binary Complements (二補數) • 1 補數 • 該數與其 1補數相加 • 再加上 1
二補數加減法的例子 • 88 與 10 的二進位與二補數 • 88-10 的二補數減法過程
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?
3.3.3 Most Significant Bit as a Sign Indicator • A 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
3.3.5 MSB and Number of Bits • Since 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. • 以下位元串到底代表甚麼數字呢?
3.3.6 Issues Surrounding the Conversion of Binary Numbers • 2 補數正數轉為十進位 • 2 補數負數轉為十進位
最大最小值 • 2 補數 • 正負號位元表示法
指數 • 10n • 2n
符點數解碼 • 請問下列32 位元浮點數代表何值 11010110101101101011000000000000
符點數編碼 • 請將下列二進位數編為浮點格式 • 0.000000110110100101 步驟 1: 步驟 2: 步驟 3:
16 進位加法範例 • 請計算 3DA32 加上 4292F 的結果
用移位代替乘法 • 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 的填入值
用移位代替乘法 (C 語言版) • 乘以 8 • 除以 16
3.8 Easy Decimal to Binary Conversion Trick • 將 15610 轉為二進位 • 所以 15610 的 2 進位為 10011100
3.9 Arithmetic Overflow (溢位) • 20010 = 1 1 0 0 1 0 0 0 • 17510 = 1 0 1 0 1 1 1 1 • 20010 + 17510 溢位