Closed sdarnell closed 9 years ago
The problem is that |
has a higher priority than <<
so only the last expression ((((uint)a[3] & 0xff) << 24)
will have the right shift applied to it.
Another solution for you is to add another set of parentheses:
uint v = (uint)( ((uint)a[0] & 0xff) | (((uint)a[1] & 0xff) << 8) | (((uint)a[2] & 0xff) << 16) | (((uint)a[3] & 0xff) << 24) >> 0);
which does work.
The solution probably has to be to implement an int
to uint
conversion that handles negative values correctly. (related to #335)
Oh dear I'll have to turn up the volume on my glasses ;) I was convinced that there where brackets around all of the ORs before the >> 0
, but there aren't.
As you say, the ideal would be for a (uint) cast from int to do a >>> 0
, but I appreciate that is part of #335.
So I'm more than happy for this issue to be closed if you'd prefer.
There's some code which generates the wrong value due to order/lack of brackets, here's the original code:
The resulting JS is:
I have a temporary work-around which forces the brackets: