Onl*_*ons 0 language-agnostic math numbers twos-complement number-systems
什么是2的补充数?
为什么我们采用1的补语并加1?为什么我们在服用1次补体后不减1?
为什么计算机使用2的补码?
小智 6
什么是2的补充数?
互补数字系统用于表示负数.因此,2的补数系统用于表示负数.
UPDATE
Q: What “2’s Complement System” says?
Run Code Online (Sandbox Code Playgroud)
A: The negative equivalent of binary number is its 2’s complement. (1’s Complement + 1)
注意:需要1个额外位来表示数字的符号.MSB(最高有效位)用作符号位.如果MSB为0,则该数字为正数.如果MSB为1,则该数字为负数.
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?
Run Code Online (Sandbox Code Playgroud)
MSB用作符号,如果为1,则为负,如果为0则为正.
-1 * 2^2 + 0*2^1 + 0*2^0 = -4 + 0 + 0 = -4
Run Code Online (Sandbox Code Playgroud)
类似地,101(3位)是-3
-1 * 2^2 + 0*2^1 + 1*2^0 = -4 + 0 + 1 = -3
Run Code Online (Sandbox Code Playgroud)
观察:
• 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.
Run Code Online (Sandbox Code Playgroud)
为什么我们采用1的补语并加1?为什么我们在服用1次补体后不减1?
请参阅以下链接中的"为什么反转并添加一个工作"主题.如果我开始解释,这篇文章会变得很大. http://www.cs.cornell.edu/~tomf/notes/cps104/twoscomp.html
为什么计算机使用2'补充?