 # RGB to Hex conversion

I have some color lights which use RGB colors and I would like to use their colors in HR tiles icons and background. Is there a way to do it? How can I convert RGB to Hex? Many thanks!

The conversion between the two is not trivial. I would suggest googling “RGB to Hex”. It should bring up suggestions for commercial web site converters, and some of them are at no cost.

David, many thanks for your reply. It took me a while, but I managed to implement the conversion in HR, it is not very complicated and it seems to work Just in case anyone is interested, I attach my code:

``````function RGBtoHex (r, g, b) {
//console.log("---> RGB: "+ r +"," + g + "," + b + "  =  #" + toHex(r) + toHex(g) + toHex(b));
return "#" + toHex(r) + toHex(g) + toHex(b);
}

function toHex(n) {
var hex = n.toString(16);
while (hex.length < 2) {
hex = "0" + hex;
}
return hex;
}
``````

In fact, ypu might want to add the white RGB component or others, so I modified the function with an array argument to be able to pass any number of parameters of 255 integers, as follows:

``````function RGBXtoHex (rgbx) {
var fullHex = "#";
for (var i = 0; i < rgbx.length; i++) {
var hex = rgbx[i].toString(16);
while (hex.length < 2) {
hex = "0" + hex;
}
fullHex = fullHex + hex;
}
//console.log("---> RGBX: " + rgbx + "  =  " + fullHex);
return fullHex;
}
``````