When i try to run the following code it prints "FALSE" instead of "TRUE" Can somebody explain why the code returns false?
#include <stdio.h>
int main(void)
{
if(-8 & 7)
{
printf("TRUE");
}
else
{
printf("FALSE");
}
return 0;
}
-8 can be represented the following way ( I will use a byte representation
That is
-8
in the two-complement representation is equal tp~8 + 1
So
-8
is equal to11111000
and7
is equal to00000111
that is the binary AND operation yields a false result.
7
is represented as00000111
in binary.-8
is represented as11111000
in binary. The bitwise AND operation performs an AND on every bit:Hence, the if condition is false.