Skip to content

Instantly share code, notes, and snippets.

@tmathews
Created April 1, 2014 20:15
Show Gist options
  • Save tmathews/9922200 to your computer and use it in GitHub Desktop.
Save tmathews/9922200 to your computer and use it in GitHub Desktop.
hex
function hex ( n ) {
//See: http://www.javascripter.net/faq/rgbtohex.htm
n = parseInt(n,10);
if (isNaN(n)) return "00";
n = Math.max(0,Math.min(n,255));
return "0123456789ABCDEF".charAt((n-n%16)/16)
+ "0123456789ABCDEF".charAt(n%16);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment