Skip to content

Instantly share code, notes, and snippets.

@ardcore
Created February 20, 2013 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ardcore/4995572 to your computer and use it in GitHub Desktop.
Save ardcore/4995572 to your computer and use it in GitHub Desktop.
rgb to hex
function rgbToHex(r, g, b) {
var ret;
return [ r, g, b ].map( function(val) {
ret = val.toString(16);
return ret.length == 1 ? "0" + ret : ret;
}).join("");
}
@michalbe
Copy link

function rgbToHex(r, g, b) {
  return ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).substr(1);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment