Skip to content

Instantly share code, notes, and snippets.

@rdela
Forked from jed/LICENSE.txt
Created July 2, 2012 18:36
Show Gist options
  • Save rdela/3034799 to your computer and use it in GitHub Desktop.
Save rdela/3034799 to your computer and use it in GitHub Desktop.
convert HEX to RGB
function(
a // take a "#xxxxxx" hex string,
){
a = +( // turn it into a number by taking the
"0x" + // hexadecimal prefix and the
a.slice(1) // numerical portion,
.replace( // and
a.length > 4 // if the #xxxxxx form is used
&& /./g, // replace each character
'$&$&' // with itself twice.
)
);
return [ // return an array
a >> 16, // with red,
a >> 8 & 255, // blue,
a & 255 // and green components.
]
}
function(a){a='0x'+a.slice(1).replace(a.length>4&&/./g,'$&$&');return[a>>16,a>>8&255,a&255]}
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": "hex2rgb",
"description": "Converts a hex string to RGB.",
"keywords": [
"hex",
"color",
"rgb"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment