A) (Int32)X | ((Int32)Y << 16);
B) (Int32)X + (Int32)Y * (Int32)Int16.MaxValue;
Shouldn’t both be equivalent? I know from testing that the first works as expected, but for some reason the second doesn’t. Both X and Y are shorts (Int16), and the return type is an integer (Int32).
Shouldn’t Y << 16 <=> Y * Int16.MaxValue?
To get the desired behaviour, you need to multiply with
0x10000(i.e.UInt16.MaxValue+1).Int16.MaxValueis0x7fff.Compare to the decimal system: If you want to “shift” the number 5 to 500, you need to multiply with 100, not 99 🙂