kamagra bombone novi sad

Monday, August 29, 2016

RGB-to-Hex Conversion

November 3, 2009 by · Leave a Comment 

Question is: How do I convert RGB values of a color to a hexadecimal string?

The algorithm is as follows: make sure that RGB values are in the range 0…255, convert RGB values to hex strings, and then merge the three strings.
Here is a script that does this conversion:

function RGBtoHex(R,G,B)
return toHex(R)+toHex(G)+toHex(B);

function toHex(N)
if (N==null)
return "00";
if (N==0 || isNaN(N))
return "00";
return "0123456789ABCDEF".charAt((N-N%16)/16)
+ "0123456789ABCDEF".charAt(N%16);

For reference and online example Click Me

Top Blogs

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!