2的补码是多少? [英] What is 2's Complement Number?
问题描述
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: The negative equivalent of binary number is its 2’s complement. (1’s Complement +
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'补码?
- 硬件较少的Cos.如果计算机使用的是2'补码, 它使用加法电路进行减法.因此,硬件更少!
- 如上例所示,+ 0和-0具有相同的表示形式. (1的补码和符号幅度表示法对于+0和-0有2种不同的表示法.)
- (不重要),您将可以使用2的补码表示一个额外的数字. (在上面的示例中,它的-4表示二进制,使用3位为'100').
- Cos' of less hardware. If the computer is using 2' Complement means, it does subtraction using addition circuit. So, less hardware!!!
- As seen in the above example, +0 and -0 have same representation. (1's complement and sign magnitude representation have 2 different representation for +0 and -0).
- (Not an important) You will be able to represent one extra number using 2's complement. (in the above example its -4 which is '100' in binary using 3 bits).
这篇关于2的补码是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!