While solving problems, I stuck here thinking how the output of this program gives ffffffff
. Since the left shift of bits should give -2. I cross-checked here Online Calculator giving -2. I can see the binary value of -1 is 11111111. But how?
Also, my observance from here Signed int conversion:
-1 ---> 0xff --> 1111 1111
-2 ---> 0xfe --> 1111 1110
-3 ---> 0xfd --> 1111 1101
-8 ---> 0xf8 --> 1111 1000
#include<stdio.h>
int main()
{
printf("%x", -1<<1);
getchar();
return 0;
}
Please tell me how the compiler looks integers below 0 when bitwise shift operators are used?