function androidToRgba(color){
const colorArray = []
for(let i=0; i<4; i++){
colorArray.push(color % 256)
color>>>=8
}
const alpha = colorArray.pop() / 255
return `rgba(${colorArray.reverse()},${alpha})`
}
console.log(androidToRgba(4294933099))
console.log(androidToRgba(4283744614))
console.log(androidToRgba(4293898800))
function rgbaToAndroid1(rgba) {
const c = new Uint8Array([
rgba[2],
rgba[1],
rgba[0],
Math.round(rgba[3] * 255)
]);
return new Uint32Array(c.buffer)[0];
}
// либо
function rgbaToAndroid2(rgba) {
let color = 0;
for (let i = 0; i < 3; i++) {
color += rgba[i] * 2 ** ((2 - i) * 8);
}
color += Math.round(rgba[3] * 255) * 2 ** (3 * 8);
return color;
}
console.log(rgbaToAndroid1([255, 122, 107, 1]));
console.log(rgbaToAndroid2([255, 122, 107, 1]));