I worked with bit-shift operators (see my Bit Array Equality question ), and the SO user pointed out an error in my calculation of my shift operand - I calculated the range [1.32] instead of [0.31] for int. (Hooray for the SO community!)
When fixing the problem, I was surprised to find the following behavior:
-1 << 32 == -1
Actually, it seems that the n << sCLR is compiled (or interpreted - I did not check IL) as n << s % bs(n), where bs (n) = size in bits of n.
I would expect:
-1 << 32 == 0
It would seem that the compiler understands that you are moving beyond the bounds of the target and correcting your mistake.
This is a purely academic question, but does anyone know if this is defined in the specification (I could not find anything in 7.8 Shift Operators ), is it just a random fact of undefined behavior, or is there a case where this may cause an error?
source
share