二进制补码证明
是否可以通过归纳证明,对于所有长度为 n 的序列,任何 0 字符串的二进制补码始终会导致 0?
我尝试使用值公式来执行此操作,即
value = -a_n-1 x 2^(n-1) + summation{i=0 to n} (a_i x 2^i),其中 n = 位数在字符串中
Is it possible to prove by induction that the two's complement of any string of 0's will always result in 0, for all sequences of length n?
I'm trying to do this using the value formula, i.e.
value = -a_n-1 x 2^(n-1) + summation{i=0 to n} (a_i x 2^i), where n = number of bits in string
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
111..111的2的补码不就是1(这意味着111..111代表-1)吗?
Isn't the 2's complement of 111..111 just 1 (which means that 111..111 represents -1)?
例如,您是否要求证明
1111 1111
的二进制补码是0000 0000
?如果是这样,你无法证明它,因为它是假的。1111 1111
的二进制补码是0000 0001
。对您的编辑的回应:当然。但你不需要感应。将
0_n
的所有位反转以获得补码,得到1_n
并添加1
将所有位翻转回零(1 + 1 = 10
并且进位位渗透到我们丢弃它的末尾)。量子电子器件。Are you asking to prove that, for example, the two's complement of
1111 1111
is0000 0000
? If so, you can not prove it because it is false. The two's complement of1111 1111
is0000 0001
.Response to your edit: Sure. But you don't need induction. Inverting all of the bits of
0_n
to obtain the one's complement gives you1_n
and adding1
flips all the bits back to zero (1 + 1 = 10
and the carry bit percolates through to end where we drop it). QED.1) X 的二补定义:翻转 X 和 sum 1 的位
2) 两个变量的二进制和为 1 位 (http://www.play-hookey.com/digital/adder.html) (即 b1第一个变量和 b2 第二个变量 b1:X 表示变量中的位 X)
2.1) 如果 b1:1 和 b2:1 两个位均为
3) 具有 2 位的两个变量的二进制和
3.1) 从 2.1 我们可以减少
4 ) 是一个数字零全零。翻转所有位将生成全 1 数字: Ones
5) Bit 0 XOR Anything = Anything(XOR 真值表)
6) 对数字 0 应用 (1)
6.1) 翻转
6.2) sum 1
6.3) 由于 N_One 中除 N_One 之外的所有位:1 为零。
6.4) 来自 3.1
由于第一个进位 (carry:1) 被定义为 1,所以来自 6.1 所有进位都被定义为 1
7) 来自 6.3 和 6.4
对于任何 n 值,证明 (~n+1) 始终为 0。(具有固定位域大小的机器的最后进位总是被忽略)
QED
1) Definition of two complement of X: flip the bits of X and sum 1
2) Binary sum of two variables with 1 bit (http://www.play-hookey.com/digital/adder.html) (being b1 the first variable and b2 the second variable. b1:X denote bit X in the variable)
2.1) if both bits are one b1:1 and b2:1
3) Binary sum of two variables with 2 bit
3.1) From 2.1 we can reduce
4) Be a number Zero all zeros. Flipping all bits will generate an all ones number: Ones
5) Bit 0 XOR Anything = Anything (truth table of XOR)
6) Applying (1) on number Zero
6.1) flip
6.2) sum 1
6.3) As all bits from N_One except N_One:1 are zero.
6.4) from 3.1
As the first carry (carry:1) is defined as 1 from 6.1 all carries are defined as 1
7) from 6.3 and 6.4
For any value of n, proving that (~n+1) is always 0. (the last carry for a machine with fixed bitfield size is always ignored)
QED