Skip to content

Instantly share code, notes, and snippets.

@C-Rodg
Created October 31, 2017 22:24
Show Gist options
  • Save C-Rodg/5e7f7341b7b9995e62b74bb367bb16c9 to your computer and use it in GitHub Desktop.
Save C-Rodg/5e7f7341b7b9995e62b74bb367bb16c9 to your computer and use it in GitHub Desktop.
A quick script using a bitwise operator to convert a color hex string into RGB.
const convertHexToRGB = (hex) => {
hex = hex[0] === '#' ? hex.substr(1) : hex;
const rgb = parseInt(hex, 16);
return {
Red: (rgb >> 16) & 0xFF,
Green: (rgb >> 8) & 0xFF,
Blue: rgb & 0xFF
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment