In the following code when I arithmetically right shift MSB3 (which happens to be 0) by 31 I get 2.
But when I replace MSB3 by 0 I get 0, which is the result I was expecting in the first case.
Why does this happen?
const int value = 0; //This happens after adding 0x80000000 to 0x80000000
const int mask = 0x1;
const int mask2 = mask << 31;
const int MSB3 = value & mask2; // MSB3 = 0
const int trueMSB3 = (MSB3 >> 31) // This gives 2 rather than 0???
const int trueMSB3 = (0 >> 31) //Gives 0