The boolean negation operator, "!", is not a bit-wise operation. It deals with only two logical values, TRUE and FALSE. The in C language, FALSE is implemented with an integer value of 0 (zero). But TRUE could be implemented with
any non-zero integer value. It could be 00000001 or it could be 11111111. So in your example, if x=1111, z = 0. And if x=1010, z also = 0. The only time z will not be zero is if x is zero. And then z might have any non-zero value, although most C compilers implement TRUE as the integer value "1". So if x is 0, z will probably be 1.
The safest way to treat boolean variables implemented as integers is never to examine the actual values, but only use those variables in logical expressions involving operators like "!", "&&", and "||". Otherwise you can get something really strange like this:
Code:
if( booleanA == booleanB ) doSomething(); //..Bad code!!!
Even if both booleanA and booleanB are true, this code might not call doSomething(), for example if booleanA=4 and booleanB=5. The only safe way to do what the above code is trying to do is to do this:
Code:
if((booleanA && booleanB) || (!booleanA && !booleanB))
doSomething();