一些计算机科学中的小细节

  1. Q:为什么negate一个补码表示的数是各位取反末位加1?

    A:image-20250427104320796

    image-20250427105531964

    以上内容的具体实例在Computer Organization and Design MIPS Edition (sixth edition)(David A. Patterson, John L. Hennessy) 的第83、84页。

    The phrase “there are pros and cons” means that something (like a situation, decision, idea, or object) has both advantages (pros) and disadvantages (cons).

    Example:

    “Thinking about moving to the countryside? Well, there are pros and cons.

  2. Q:Two’s complement(2的补码)这个名称是怎么来的?

    image-20250427112126130

    Let’s use a simple example with n=4 bits:

    • The number x=3 in 4 bits is 0011.

    • Its 4-bit negative using two’s complement is −3, which is represented as

      1101
      • (How to get 1101 for -3: Invert bits of 0011 -> 1100. Add 1 -> 1101).
    • Now, let’s do the unsigned sum of

      0011

      and

      1101

      :

        0011  (represents 3)
      + 1101 (represents -3 in two's complement, but treated as 13 in unsigned)
      ------
      10000
    • The result is 10000. This binary number is 16 in decimal.

    • For n=4, 2n=24=16.

    • So, the unsigned sum of the 4-bit number (3) and its 4-bit negative (-3) is indeed 16。

  3. Design principle 3 : Good design demands good compromises.