#Hi, I need someone to explain me that why the output of the below given code snippet comes -11 .

8 messages · Page 1 of 1 (latest)

white spade
#

#include <stdio.h>

void main(){
unsigned int a=10;
a=~a;
printf("%d\n",a);
}

shut elk
#

thats BITWISE NOT operator, it not really giving 11 (eleven) but 1-1 (one-one)

warped compass
#

I don't think so

#

If you inverse the bits of the number 10, you get 11110101 which is equal to -11

shut elk
#

its a real thing, Bitwise not is invert of bits NOT value
decimal 10 is 1010 in binary, and invert of 1010 is 0101,
0101 is equal to -11 in 2s compliment

warped compass
#

"0101" isn't -11, it's 5 in 2's complement

#

11110101 is -11

shut elk
#

yes, i used 4bit seperation