cast hash higher precedence than both assignment and shift.
Code: Select all
i = (uint16_t)(0x1F784 >> 16); //1
0x1F784 defaults defautls to int, 32 bits. After shifting, you obtain 0x1 (still int, 32 bits). Then you cast to uint16_t, truncating the two upper bytes. Then you assign to an integer, that becomes 0x1.
0x1F784 defaults defautls to int, 32 bits. Then it gets cast to uint16_t, truncating the two upper bytes. Then you shift right by 16 bits, discarding everything and assigning a 0.
I think that this one is clear, right?
Anyway, I personally find a bit hard to remember all the precedences for different operators and I prefer to explicitly add round brackets that show the precedence.