为什么这个按位运算符返回负数?

时间:2014-08-25 07:16:02

标签: c bitwise-operators

我刚刚阅读了按位运算符的教程,我不明白为什么这个数字是-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

1 个答案:

答案 0 :(得分:0)

不,不应该!

您可能希望将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