Last active
August 23, 2019 01:23
-
-
Save grough/4a737fe1aa6819e239b88cf79ff62048 to your computer and use it in GitHub Desktop.
Convert decimal number to RGB color components with JavaScript
This file contains 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
function decimalToRgb(decimal) { | |
return { | |
red: (decimal >> 16) & 0xff, | |
green: (decimal >> 8) & 0xff, | |
blue: decimal & 0xff, | |
}; | |
} | |
/* | |
Examples: | |
decimalToRgb(0xff8040) -> { red: 255, green: 128, blue: 64 } | |
decimalToRgb(0xffffff) -> { red: 255, green: 255, blue: 255 } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment