-2

This answer explains numbers like 4280362283 are raw decimal color codes. A library I'm using passes these. What's the algorithm to convert them? Ive throw some attempts like this against the wall but nothing stuck so far:

console.log("Dec:", arr1[0])
let num1 = parseInt(arr1[0], 16);
console.log("Hex:", num1);
let r = parseInt(num1.toString().slice(0, 3), 16);
let g = parseInt(num1.toString().slice(3, 6), 16);
let b = parseInt(num1.toString().slice(6, 9), 16);
console.log("r, g, b:", r, g, b);
J.Todd
  • 707
  • 1
  • 12
  • 34

1 Answers1

3

4280362283 looks like ARGB color could be from Android (see comment below from Kaiido). The following function is from this post

function ARGBtoRGBA(num) {
    num >>>= 0;
    let b = num & 0xFF,
        g = (num & 0xFF00) >>> 8,
        r = (num & 0xFF0000) >>> 16,
        a = ( (num & 0xFF000000) >>> 24 ) / 255 ;
    return "rgba(" + [r, g, b, a].join(",") + ")";
}

let x = ARGBtoRGBA(4280362283);

console.log(x);
zer00ne
  • 41,936
  • 6
  • 41
  • 68
  • RGBA is not an Android only thing, that's only how Little Endian hardware will represent the Uint8Array `[R,G,B,A]`: `0xAARRGGBB`. On Big Endian that would be `0xRRGGBBAA`, but BE are quite rare nowadays. – Kaiido Apr 22 '19 at 00:47