#include <iostream>
usingnamespace std;
int main()
{
int x, y;
x = 12;
y = ~x;
cout << y;
return 0;
}
As you see, value of x is equal to 12( 1100 ).
So I think the value of y is equal to 3( 0011 ).
But when I try to compile this program, the value of y is -13.
What is the problem?
An int is signed and contains more bytes so you won't get that result.
Even on an unsignedchar the result would be difference as usually bytes have 8 bits
00001100
11110011 = 243