Skip to content

Instantly share code, notes, and snippets.

@grough
Last active August 23, 2019 01:23
Show Gist options
  • Save grough/4a737fe1aa6819e239b88cf79ff62048 to your computer and use it in GitHub Desktop.
Save grough/4a737fe1aa6819e239b88cf79ff62048 to your computer and use it in GitHub Desktop.
Convert decimal number to RGB color components with JavaScript
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