Skip to content

Instantly share code, notes, and snippets.

@klarstil
Created July 1, 2013 11:17
Show Gist options
  • Save klarstil/5900036 to your computer and use it in GitHub Desktop.
Save klarstil/5900036 to your computer and use it in GitHub Desktop.
Simple method which converts a hex string (6 chars) to an array with rgb values
/**
* Private helper method which parses an hex string to a rgb.
*
* @param hexStr
* @returns {Array}
*/
var hex2rgb = function(hexStr) {
var hex = parseInt(hexStr.substring(1), 16),
r = (hex & 0xff0000) >> 16,
g = (hex & 0x00ff00) >> 8,
b = hex & 0x0000ff;
return [r, g, b];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment