什么是 2 的补数? [英] What is 2's Complement Number?

查看:23
本文介绍了什么是 2 的补数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是 2 的补数?
为什么我们取 1 的补码并加 1?取 1 的补码后为什么不减 1?
为什么计算机使用 2 的补码?

What is 2's Complement Number?
Why do we take 1's Complement and add 1 to it? Why don't we subtract 1 after taking 1's Complement?
Why do computers use 2's Complement?

推荐答案

什么是 2 的补数?

补数系统用于表示负数.所以,2的补数系统用于表示负数.

Complementary number system is used to represent negative numbers. So, 2's Complement number system is used to represent negative numbers.

更新

Q:  What "2’s Complement System" says?

A:二进制数的负数是它的 2 的补码.(1 的补码 + 1)

注意:表示数字的符号需要 1 个额外的位.MSB(最高有效位)用作符号位.如果 MSB 为 0,则该数字为正数.如果 MSB 为 1,则该数为负数.

Note: 1 extra bit is required to represent the sign of a number. MSB (Most Significant Bit) is used as sign bit. If MSB is 0, then the number is positive. If MSB is 1, then the number is negative.

1’s Complement  Value   2’s Complement
    011         +3          011
    010         +2          010
    001         +1          001
    000         +0          000
    111         -0          000
    110         -1          111
    101         -2          110
    100         -3          101
                -4          100

How '100' (3 bits) is -4?

MSB为符号,为1为负,为0为正.

MSB is used as sign, if 1, its negative, if 0 it is positive.

-1 * 2^2 + 0*2^1 + 0*2^0 = -4 + 0 + 0 = -4

同样 101(3 位)是 -3

Similarly 101 (3 bits) is -3

-1 * 2^2 + 0*2^1 + 1*2^0 = -4 + 0 + 1 = -3

观察:

•   In 1’s complement, using 3 bits, we represented 2^3 = 8 numbers i.e from -3 to +3.
•   In 1’s complement, -0 and +0 are having 2 representation. (+0 is ‘000’ and -0 is ‘111’).
    But mathematically +0 and -0 are same.
•   In 2’s complement, using 3 bits, we represented only 2^3 = 8 numbers i.e from -4 to +3.
•   In 2’s complement, -0 and +0 are having same representation.
•   Since +0 and -0 in 2’s complement is having same representation, 
    we are left out with one more combination which is ‘100’ = -4.

为什么我们取 1 的补码并加 1?为什么不取 1 的补码后减 1?

请参阅以下链接中的为什么反转和添加一个作品"主题.如果我开始解释,这篇文章会变大.http://www.cs.cornell.edu/~tomf/notes/cps104/twoscomp.html

Refer "Why Inversion and Adding One Works" topic in the below link. If I start explaining, this post will grow big. http://www.cs.cornell.edu/~tomf/notes/cps104/twoscomp.html

为什么计算机使用 2' 补码?

  • 由于硬件较少.如果计算机使用 2' 补码方式,它使用加法电路进行减法.所以,更少的硬件!!!
  • 如上例所示,+0 和 -0 具有相同的表示.(1 的补码和符号幅度表示对于 +0 和 -0 有 2 种不同的表示).
  • (不重要)您将能够使用 2 的补码表示一个额外的数字.(在上面的示例中,它的 -4 是使用 3 位的二进制100").

这篇关于什么是 2 的补数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆