int main()
{
unsigned int a = 1;
printf("%u\n",a<<(-1));
return 0;
}
The output is 2147483648.
Here is my assumption and validation:(just assumption!)
1.The "<<" right operand must be unsigned int type,
so firstly, the (int) “-1” will be cast into (unsigned int) "-1". Cause int type is two's-complement representation, the result will be 2^32-1(unsigned int)
2.Due to number 2^32-1 is larger than the Max displacement digit, 2^32 - 1 will be mod 32, which equals 27
I also tried some other nagetive right operand numbers, and the manual calculation results with assumpted rules will be the same with what product by my IDE.
I am trying to find some supporting offical documents, witch could verificate whether my assumption is right or not. Maybe you can tell me.