小编Luc*_*cas的帖子

为什么按位运算符(~)的序列会是这样?那坏了吗?

#include <stdio.h>
#include <stdlib.h>

int main() {
unsigned char a=100,b=50;

printf("%d & %d = %d\n",a,b,a&b);
printf("%d | %d = %d\n",a,b,a|b);
printf("%d ^ %d = %d\n",a,b,a^b);
printf(" ~%d = %d\n",a, ~a);       /*the out come of this  line would be this: ~100 = -101 */
printf(" %d >> 2= %d\n",a, a>>2);
printf(" %d << 2= %d\n",a, a<<2);
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)

/结果应该是 155,不是吗?/

c++ printf bitwise-operators integer-promotion

1
推荐指数
1
解决办法
139
查看次数