Created
October 31, 2017 22:24
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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