2 的补码多余 N
有人可以解释一下如何做到这一点吗?这不是家庭作业。
有人可以向我解释一下如何做到这一点吗?
Show that if N is chosen to be equal to 2^(m-1) where m is the number of bits
in the representation, then an Excess N representation will be the same as a 2's
Complement representation but with the sign bit inverted. Hint - transform the
summation formula for Excess-N numbers to the summation formula for 2's Comp
numbers.
首先,如何将N余数的求和公式转换为2的补数公式?其次,我究竟应该如何证明这一点?
Could someone please explain how to do this? It's not homework.
Could someone please explain to me how to do this?
Show that if N is chosen to be equal to 2^(m-1) where m is the number of bits
in the representation, then an Excess N representation will be the same as a 2's
Complement representation but with the sign bit inverted. Hint - transform the
summation formula for Excess-N numbers to the summation formula for 2's Comp
numbers.
First of all, how do I transform the summation formula for excess-N numbers to the formula for 2's Complement numbers? Secondly, how exactly am I supposed to prove that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
计算机中的数字存储为 m 位,其中包含 [0..(2^m)-1] 范围内的数字 - 正(无符号)数字。因此,要表示负数,您需要以某种方式将负数编码到这个空间中。有多种方法可以做到这一点,术语符号幅度、二进制补码、个数补码和多余- N 都指的是不同的方法。
Excess N 表示法意味着您通过将常数 N 添加到所有数字来处理负数,这样您就只需要处理正数。所以0的值代表-N,1的值代表-N+1,等等。N的值代表0。
现在,我不确定你指的是哪本书,但是一个求和公式 通常指的是通过对一组项求和来计算值的方法。在数字表示的上下文中,它通常为每个位分配一个“值”,这样设置位的值的总和就给出了编码的数字。当您对二补码执行此操作时,您最终会得到一个公式,而当您对Excess-N执行此操作时,您最终会得到一个稍微不同的公式,但是您应该能够看到/显示您引用的问题中的等效项。
Numbers in a computer are stored as m bits which hold a number in the range [0..(2^m)-1] -- positive (unsigned) numbers. So to represent negative numbers, you need to encode the negative numbers into this space somehow. There are number of ways of doing that, and the terms Sign-Magnitude, Twos-complement, Ones-Complement and Excess-N all refer to different way of doing that.
Excess N notation means that you deal with negative numbers by adding the constant N to all numbers, so that you only ever have positive numbers to deal with. So a value of 0 represents -N, a value of 1, represents -N+1, etc. A value of N represents 0.
Now, I'm not sure what book you are referring to, but a Summation Formula will usually refer to a way of computing a value by summing a bunch of terms. In the context of numeric representations, it usually assigns a 'value' to each bit, such that the sum of the value for the set bits gives you the number that is encoded. When you do this for Twos-complement, you end up with one formula, and when you do it for Excess-N you end up with a slightly different formula, but you should be able to see/show the equivalence in your quoted question.
我希望 MathJax 在 StackOverflow 中工作。没有它,我就得想办法解决这个问题。
N = λ1( - 2^(L - 1)) + SUM(从 n=2, 到 n=L)[λn(2^(L - n)] 是 N 的 2 补码扩展。
这里 λn E {0, 1}(位);n E Z。L
= N 中的位长度(问题有 L = m)因此
Nmax 是 SUM(从 n=2, 到 n=L)[2^(L - n)]
Nmax > = (2^(L - 1)) - 1 (简化形式)
所以,这个问题是不正确的,因为如果位的长度是 L,你甚至不能用 2 的补码表示 N = 2^(L - 1) 我们可以为N
选择一个更合适的值,例如 N = Nmax,
则 λn = { 0 for n = 1; 1 for n in [2, L ] }; n EZ
因此,N 的 2 补码二进制表示为 (0,1,1,...1)b,其中
N = NE 。 - E,其中 NE 是 N 的 Excess-N 版本,E 是 Excess。
我们知道 E = 2^(L - 1)。 wikipedia.org/wiki/Offset_binary" rel="nofollow noreferrer">Excess-N 维基百科文章
NE = SUM(从 n=1, 到 n=L)[αn(2^(L - n))] 是 NE 的 2 次方展开式。
这里,αn E {0, 1}(比特); [1,L]中的n; n EZ
N = NE - E
NE = N + E
NE = N + 2^(L - 1)
NE = N最大 + 2^(L - 1)
NE = ((2^(L - 1)) - 1) + 2^ (L - 1)
NE = SUM(从 n=2 到 n=L)[2^(L - n)] + 2^(L - 1)
NE< /sub> = SUM(from n=1, to n=L)[2^(L - n)]
接下来,我们替换 NE 的扩展:
NE = SUM(从 n=1, 到 n=L)[2^(L - n)]
SUM(从 n=1, 到 n=L)[αn(2^(L - n))] = SUM(from n=1, to n=L)[2^(L - n)]
这意味着 αn = 1 for n in [1, L]; n EZ
因此,N 的 Excess-N 二进制表示为 (1,1,1,...1)b,具有 L 位。
比较这两种表示法,我们可以看到,简单地翻转一种表示法中的 MSB 就会产生另一种表示法。
I whish MathJax worked in StackOverflow. I'll just have to wrangle my way through this without it.
N = λ1( - 2^(L - 1)) + SUM(from n=2, to n=L)[λn(2^(L - n)] is the 2's compliment expansion of N.
Here λn E {0, 1} (bits); n in [1, L]; n E Z.
L = length of bits in N. (The question has L = m).
Nmax is thus SUM(from n=2, to n=L)[2^(L - n)]
Nmax = (2^(L - 1)) - 1 (simplified form)
So, the question is incorrect since you can't even represent an N = 2^(L - 1) in 2's compliment if the length of bits is L.
We can choose a more appropriate value for N, say N = Nmax.
Then λn = { 0 for n = 1; 1 for n in [2, L] }; n E Z
So, the 2's compliment binary representation of N is (0,1,1,...1)b with L bits.
N = NE - E where NE is the Excess-N version of N and E is the Excess.
We know that E = 2^(L - 1). Excess-N Wikipedia Article
NE = SUM(from n=1, to n=L)[αn(2^(L - n))] is the powers-of-2 expansion of NE.
Here, αn E {0, 1} (bits); n in [1, L]; n E Z
N = NE - E
NE = N + E
NE = N + 2^(L - 1)
NE = Nmax + 2^(L - 1)
NE = ((2^(L - 1)) - 1) + 2^(L - 1)
NE = SUM(from n=2, to n=L)[2^(L - n)] + 2^(L - 1)
NE = SUM(from n=1, to n=L)[2^(L - n)]
Next, we substitute the expansion of NE:
NE = SUM(from n=1, to n=L)[2^(L - n)]
SUM(from n=1, to n=L)[αn(2^(L - n))] = SUM(from n=1, to n=L)[2^(L - n)]
Which implies that αn = 1 for n in [1, L]; n E Z
So, the Excess-N binary representation of N is (1,1,1,...1)b with L bits.
Comparing the two representations, we can see that simply flipping the MSB in one notation produces the other.