C#: Shift left assignment operator behavior

Posted by Austin Salonen on Stack Overflow See other posts from Stack Overflow or by Austin Salonen
Published on 2010-03-24T05:28:35Z Indexed on 2010/03/24 5:33 UTC
Read the original article Hit count: 347

Filed under:
|

I'm running code that sometimes yields this:

UInt32 current;  
int left, right;  

...

//sometimes left == right and no shift occurs
current <<= (32 + left - right);

//this works
current <<= (32 - right);
current <<= left;

It appears for any value >= 32, only the value % 32 is shifted. Is there some "optimization" occurring in the framework?

© Stack Overflow or respective owner

Related posts about c#

Related posts about bitwise-operators