关于算术右移运算符的问题
Question on arithmetic right shift operator
我在处理这个特定操作时遇到了一些麻烦-
0x44 >> 3
其中 >> 是算术右移运算符。
现在,我所指的教科书给出的答案是 1110 1000
然而,我是这样做的-
0x44
=> 0100 0100
现在,由于第一位是零,我将算术右移的结果计算为 0000 1000
(十六进制值 0x08)
但是,这本书给出的答案是 1110 1000
(十六进制值 0xE9
)
我在这里做错了什么?
(书是CS:APP,有兴趣的可以练习题2.16)
据我所知,这是 Computer Science: A Programmer's Perspective(第 3 版)global edition 中的练习题 2.16,根据原作者错误百出。
直接引用自errata page:
Note on the Global Edition: Unfortunately, the publisher arranged for the generation of a different set of practice and homework
problems in the global edition. The person doing this didn't do a very
good job, and so these problems and their solutions have many errors.
We have not created an errata for this edition.
网上的建议似乎是,如果您对做练习题和家庭作业感兴趣,就选择北美版。
您的回答确实是正确的:
0x44 >> 3 == 0x08
我在处理这个特定操作时遇到了一些麻烦-
0x44 >> 3
其中 >> 是算术右移运算符。
现在,我所指的教科书给出的答案是 1110 1000
然而,我是这样做的-
0x44
=> 0100 0100
现在,由于第一位是零,我将算术右移的结果计算为 0000 1000
(十六进制值 0x08)
但是,这本书给出的答案是 1110 1000
(十六进制值 0xE9
)
我在这里做错了什么?
(书是CS:APP,有兴趣的可以练习题2.16)
据我所知,这是 Computer Science: A Programmer's Perspective(第 3 版)global edition 中的练习题 2.16,根据原作者错误百出。
直接引用自errata page:
Note on the Global Edition: Unfortunately, the publisher arranged for the generation of a different set of practice and homework problems in the global edition. The person doing this didn't do a very good job, and so these problems and their solutions have many errors. We have not created an errata for this edition.
网上的建议似乎是,如果您对做练习题和家庭作业感兴趣,就选择北美版。
您的回答确实是正确的:
0x44 >> 3 == 0x08