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/1002267 to your computer and use it in GitHub Desktop.
Save christopherdebeer/1002267 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[4] // if the #xxxxxx form is used
? a // replace the original string (never matches)
: /./g, // or 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[4]?a:/./g,'$&$&')|0;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