Skip to content

Instantly share code, notes, and snippets.

@christopherdebeer
Forked from jed/LICENSE.txt
Created June 1, 2011 13:16
Show Gist options
  • Save christopherdebeer/1002266 to your computer and use it in GitHub Desktop.
Save christopherdebeer/1002266 to your computer and use it in GitHub Desktop.
convert RGB to HEX
function(
a, // red, as a number from 0 to 255
b, // green, as a number from 0 to 255
c // blue, as a number from 0 to 255
){
return "#" + // return a number sign, plus
( // a number calculated by using
c | // blue as is,
b << 8 | // green shifted up two digits,
a << 16 | // red shifted up four digits,
1 << 24 // and 1 shifted up six digits,
)
.toString(16) // then serialize to a hex string, and
.slice(1) // remove the 1 to get the number with 0s intact.
}
function(a,b,c){return"#"+(c|b<<8|a<<16|1<<24).toString(16).slice(1)}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "rgb2hex",
"description": "Converts RGB colors to a hexadecimal string.",
"keywords": [
"color",
"css",
"hex",
"rgb"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment