int a = b >> 32 doesn't work properly

Jun 26, 2013 at 1:46 AM
Hi. I've got a problem. Rotating int right doesnt work properly.

There's
int b = 15;

int a = b >> 8; // a = 0
int a = b >> 16; // a = 0
int a = b >> 24; // a = 0
int a = b >> 32; // a = 15
int a = b >> 40; // a = 0
... // a = 0


SHR (>>) works for every value, but not for 32 like in the example above. I've been testing it several times and still nothing. Is there any way to repair this? Thanks.
Coordinator
Jun 26, 2013 at 7:55 AM
The values you right shift by are number of bits.
From http://msdn.microsoft.com/en-us/library/336xbhcz(v=vs.80).aspx
The results are undefined if the right operand of a shift expression is negative or if the right operand is greater than or equal to the number of bits in the (promoted) left operand.
Jun 26, 2013 at 5:32 PM
thank you :)