Possible Duplicate:
Right shifting negative numbers in C
This question i have found on SO, but everywhere i found the result as undefined.
int main()
{
printf("%d\n",32<<-2); <-------------1
printf("%d\n",32>>-2); <-------------2
return 0;
}
I am getting the output as: http://ideone.com/fIaXo
8
128
It seems that in the statement numbered 1, 32 is shifted 2 times right while in the second, 32 is being shifted 2 times left.
Is it really the case that when a value is shifted left by -p, the compiler treats it as shifting p times right?
Why am i getting the correct output here?