这是我的计算机体系结构书中的错误吗?

发布于 2024-08-11 04:55:51 字数 408 浏览 2 评论 0原文

我正在研究计算机体系结构的硬件,遇到了以下问题:

A = 247
B = 237

1) 假设 A 和 B 是以二进制补码格式存储的有符号 8 位整数。使用饱和算术计算 A + B。结果应以十进制书写。展示你的作品。
2) 假设A和B是以二进制补码格式存储的有符号8位整数。使用饱和算术计算 A - B。

现在,这些问题怎么可能是有效的呢?我知道什么是饱和算术,但是当 A 是 247 和 B 是 237 不能用 8 位二进制补码数表示时,这怎么有效呢?

我意识到饱和算术的要点是在上溢/下溢的情况下将所有位设置为极值,但对我来说提出一系列问题没有意义(还有 3 个同样的问题)涉及无法以其指定的格式表示的数字的算术。

我这里错了吗?

I'm working on my HW for computer architecture and I came across the following problem:

A = 247
B = 237

1) Assume A and B are signed 8-bit integers stored in two's complement format. Calculate A + B using saturating arithmetic. The result should be written in decimal. Show your work.
2) Assume A and B are signed 8 bit integers stored in two's compelemnt format. Calculate A - B using saturating arithmetic.

Now, how are these even a valid questions? I know what saturating arithmetic is, but how is it valid to say that A is 247 and B is 237 when they can't be represented by an 8-bit two's complement number?

I realize the point of saturated arithmetic is in the case of a overflow/underflow to set all the bits to the extreme value but it doesn't make sense to me to ask a series of questions (there are 3 more with this same problem) involving arithmetic of numbers that can't be represented in the format they specify.

Am I wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

愁杀 2024-08-18 04:55:51

唯一有意义的解释是给出的值是相关数字的无符号解释;大于 127 的值显然超出了 8 位有符号二进制补码值的范围。不过,我同意这个问题表述得不好。

The only interpretation that makes sense is that the values given are the unsigned interpretation of the number in question; values greater than 127 are obviously out of range for an 8-bit signed twos-complement value. I agree that the question is poorly stated, however.

狼性发作 2024-08-18 04:55:51

我不知道,但它可能会问:“将十进制数 237 转换为 8 位整数。现在将这些位解释为 8 位 2 的补码整数并将它们相加”。

有点像在 C 中这样说:

char a = 237;
printf("%x %d\n",a, a);

根据 8 位值“237”的 2 的补码解释,编译并给出您期望的值

I don't know, but it might be asking: "Convert the decimal number 237 to an 8-bit integer. Now interpret those bits as an 8-bit 2's complement integer and add them".

Kinda like saying, in C:

char a = 237;
printf("%x %d\n",a, a);

Which compiles and gives you values that you would expect based on the 2's complement interpretation of the 8-bit value "237"

冰雪之触 2024-08-18 04:55:51

我觉得不对。 8 位有符号二进制补码整数可以介于 -128 和 127 之间。任何将常量 2​​37 或 247 分配给 8 位有符号二进制补码变量的尝试都会导致错误,具体取决于您的语言。

Looks wrong to me. 8-bit signed two's complement integers can be between -128 and 127. Any attempt to assign a constant 237 or 247 to an 8-bit signed two's complement variable should result in an error, depending on your language.

哎呦我呸! 2024-08-18 04:55:51

如果问题是“假设 A 和 B 存储在一个 8 位有符号整数中”,那么它就有意义了。将 A = 247 存储在有符号 8 位整数中会产生值 -9,存储 B = 237 会产生值 -19。否则,就没有意义。有符号 8 位整数的值不能为 247 或 237。

If the problem was "assume that A and B are stored in an 8 bit signed integer", then it would make sense. Storing A = 247 in a signed 8 bit integer yields a value of -9, storing B = 237 yields a value of -19. Otherwise, it doesn't make sense. A signed 8 bit integer cannot have a value of 247 or 237.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文