gpt4 book ai didi

c - "Beginning C from Novice to Professional"中右移的用法误区

转载 作者:太空宇宙 更新时间:2023-11-04 03:12:50 26 4
gpt4 key购买 nike

我不确定这个右移怎么等于0:我明白移位是如何工作的,但为什么作者说它在二进制零中等于而在十进制中却有不同的结果?二进制零和十进制零不一样吗?

0000

还有它怎么等于二进制零?

unsigned int value = 65372U;

As a binary value in a 2-byte variable, this is:

1111 1111 0101 1100

Suppose you now execute the following statement:

unsigned int result = value >> 2; /* Shift right two bits */

The bits in value will be shifted two places to the right, introducing zeros at the left end, and the resultant value will be stored in result. In binary this will be 0, which is the decimal value 16343.

0011 1111 1101 0111

最佳答案

你的假设是正确的。二进制 0 与整数 0 相同。这本书往好了说是打印错误,往坏了说是完全错误。不过,它的示例似乎还不错。

另外,郑重声明,二进制 0 就是您所期望的:

0000 0000 0000 0000

0011 1111 1101 0111 不等于 0。

关于c - "Beginning C from Novice to Professional"中右移的用法误区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54714703/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com