【发布时间】:2015-04-18 01:47:37
【问题描述】:
我正在阅读有关位运算符的一章,我遇到了 1 的补码运算符程序并决定在 Visual C++ 上运行它。
int main ()
{
unsigned char c = 4, d;
d = ~c;
printf("%d\n", d);
}
它给出了有效的输出:251
然后我决定不使用d作为变量来保存~c的值,而是直接打印~c的值。
int main ()
{
unsigned char c=4;
printf("%d\n", ~c);
}
它给出了输出-5。
为什么没用?
【问题讨论】:
-
提示:
4的 1 的补码等价于-5的二进制补码表示 -
@LưuVĩnhPhúc 你的补充值得称赞。
标签: c variables types bitwise-operators unsigned-char