我刚刚阅读了有关按位运算符的教程,但我不明白为什么这个数字是 -61。
unsigned int a = 60; /* 60 = 0011 1100 */
unsigned int b = 13; /* 13 = 0000 1101 */
int c = 0;
c = ~a; /*-61 = 1100 0011 */
printf("Line 4 - Value of c is %d\n", c );
11000011不应该是195吗? (128+64+2+1)
http://www.tutorialspoint.com/cprogramming/c_bitwise_operators.htm
最佳答案
不,不应该这样!
您可能希望对所有参数使用unsigned char
unsigned char a = 60;
unsigned char b = ~a;
char c = ~a;
printf("b=%d\nc=%d\n", b, c);
给出输出:
b=195
c=-61
关于c - 为什么这个按位运算符返回负数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25480752/