Why the result of ~10 is -11? Shouldn't it be 5 as the ~ operations flips every bit.
10 = 1010
~10= 0101 //5 in decimal
unsigned int b =10;
printf("bitwise %d\n ",b);
Don't forget that you are flipping every bit, including the most significant bit (sign bit for signed variables). Defining a variable as unsigned doesn't change the binary representation, only how the program uses it.
So when you print the number out as signed (
%d) you will get -11.
10 = 0x0000000A (10) ~10 = 0xFFFFFFF5 (-11 signed / 4294967285 unsigned)
To print out as unsigned use:
printf("bitwise %u\n ",b);