1

I have task to work with colors. From API i got color Argb value (as i understood it's an 32 bit integer value), for example -65536, which i convert to hex using next function:

argbToHex: function(color) {
    return '#'+ ('000000' + (color & 0xFFFFFF).toString(16)).slice(-6);
}

as resalt i'm getting hex color number:

#ff0000

but i need to do reverse operation, convert this hex back to Argb format with result:

-65536

i tried do something like that:

function (hex){
    let parsedHex = hex.replace('#', '0x');
    return parseInt(hex, 32);
}

and lot's of other variants, but nothing gave me expected result.

Any ideas?

Thanks!

Yafim Dziuko
  • 83
  • 1
  • 2
  • 8
  • This should help with your problem: http://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hex-in-javascript – domyos Aug 22 '16 at 15:06
  • works for me! thanks! but if i want convert to 32 bit, why parseInt(hex, 16); ? @domyos – Yafim Dziuko Aug 22 '16 at 15:10
  • parseInt takes the base of the input (the hex variable) as the second parameter not your desired output. – domyos Aug 22 '16 at 15:12

0 Answers0