这段代码是做什么的s &= ~1U
如果s=8
?
我认为它必须用二进制做一些事情,但不知道到底是什么?
提前致谢!
最佳答案
为了简单起见,我在这里将其写成 1 字节二进制(8 位数字)。
s = s & ~1 // U means "unsigned"
s = 8 & ~(0b00000001) // Here is the binary representation of 1
s = 8 & 0b11111110 // ~1 is 254
s = 0b00001000 & 0b11111110
s = 0b00001000
s == 8 // Final Answer.
通过在 IDEOne 上运行代码可以确认这一点
输入
#include <stdio.h>
int main(void) {
int s = 8;
s &= ~1U;
printf("%d\n", s);
return 0;
}
输出
Success #stdin #stdout 0s 9424KB
8
关于c - C 中的运算符 &= 和 ~1U,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55172097/