Skip to content

Review Chap 2

  • Bits: We represent the presence of voltages as “1” and the absence of a voltage as “0”. We refer to each 0 and each 1 as a “bit”, which is shortened from binary digit.
  • Precisely, the electronic circuits in the computer differentiate voltages close to 0 from voltages far from 0.
  • With k bits, we can distinguish 2^k distinct items at most.
  • Data Types: 1. 2’s complement integers for representing positive and negative integers that we wish to perform arithmetic on, 2. ASCII codes for representing characters that we wish to input to a computer via the keyboard or output from the computer via a monitor(These are two data types which will be used in following chapters)
  • Integer data types

    1. Unsigned Integers.(我寻思着这玩意我还是会的)with k bits,we can represent 2^k integers,ranging from 0 to 2^k -1.
    2. Signed Integers. (用中文)正数以0为先导,负数以1为先导,with k bits,we can represent 2^k -1 integers,ranging from - 2^(k -1)-1 to 2^(k -1)-1. 但是出现了-0(如在五位当中,10000表示-0而00000表示0,这就尴尬了)
    3. 1’s complement integers(反码,似乎不重要)
    4. 2’s complement integers (补码,很重要,一会展开讲)

    Untitled

  • 关于补码的引入,书中从底层实现的角度给出了解释,进行归纳的话我认为主要是这两个因素:① 2's complement 中“溢出”与“取模”的关系;② ALU 模块只进行加法运算,而不能进行减法运算;(需要注意的是,所谓的符号位是给人看的,或者说只是一个特征。在实际过程中并不存在“符号位”,即该位也参与加法计算)

我觉得二进制加法我还不至于不会,这里省了。

  • Conversion Binary to Decimal
    1. examine the leading bit b7 to determine whether it is positive or negative.If it is negative, do step 2 after flipping all the bits and adding 1.
    2. then simply: b6 2^6+b5 2^5+…+b0 *2^0
    3. get the result, then if it is negative, don’t forget the minus sign.
  • Conversion Decimal to Binary

    1. obtain the binary representation of the magnitude of N by forming the equation N=b6⋅2^6+b5⋅2^5+…+b0⋅2^0. and repeating and following,until the left side of the equation is 0: a.If N is odd,the rightmost bit is 1.If N is even,the rightmost bit is 0. b.Subtract 1 or 0(according to whether N is odd or even)from N,remove the least significant term from the right side,and divide both side sof the equation by 2.
    2. if it is positive, add a leading 0 then finished.
    3. if it is negative, add a leading 0 and then form the negative of this 2’s complement representation, and then you are done.
  • Specially for floating point data type

    • 1 bit for the sign (positive or negative)
    • 8 bits for the range (the exponent field)
    • 23 bits for precision (the fraction field) 数据部分,但是组织形式有一些微妙,“第一位”是0还是1有特殊的处理方式

    Untitled

    • They are mostly in normalized form: (不需要考虑补码)

      https://cdn.nlark.com/yuque/__latex/037c64c8fbf18f1fa3486b7f549ebb4b.svg

  • exponent=00000000——subnormal numbers

  • exponent=11111111——infinity
  • Sign-extension (SEXT)
  • The value of a positive number does not change if we extend the sign bit 0 as many bit positions to the left as desired. Similarly, the value of a negative number does not change by extending the sign bit 1 as many bit positions to the left as desired.
  • 也就是说按照符号位向高位扩展,且这种扩展是不会影响原来的值的。
  • Overflow
  • 最高位(比如符号位)进位后不会创建一个更高位来存储这个进位信息,而是直接丢弃这个进位,也就是“溢出”,在数学层面来看,就类似于取模,比如,对应1110 + 1001 = ~~1~~0111

    https://cdn.nlark.com/yuque/__latex/5b8307da33e4ddcbecd7ca8925c4aaca.svg