I have an array of ints
var ints = [R,B,G,A]
and I want to use shifting to get a 32-bit representation
var thirtyTwo = AGBR
so for example,
[255.0, 0.0, 0.0, 255.0] => 0xFF0000FF => 4278190335
I'm attempting to do this with a loop and bitshift:
function cArrayToABGR(va) {
var res = 0;
for (var i = 0; i < va.length; ++i) {
var color = va[i];
color <<= (8 * i);
res += color;
}
return res;
}
But the main problem is when I bitshift 255.0 << 24, I get a negative number
255.0 << 24 = -16777216
which tells me I either hit a bit limit or the res is signed. I thought all bitwise operations in Javascript are on unsigned 32 bit floats, so not sure what's going on here. Help?