#include <stdio.h>
int main()
{
short int a,b;
a=1;
b=1;
if ( (a | 65534)&1 == (b | 65534)&1 )
{
printf("The rightmost bit is the same");
}
else
{
printf("The rightmost bit is different");
}
return 0;
}
}
Output: The rightmost bit is different
Expected: The rightmost bit is the same
Here the "==" is run before "&" which is not desirable. I can take another variable to fix this but not taking another variable is sort of the point of this assignment...
Add more parenthesis:
if ( ((a & 65534)&1) == ((b & 65534)&1) )