Skip to content

Instantly share code, notes, and snippets.

@hariedo
Created March 29, 2024 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hariedo/0c0a7f2bc72da70f53a6bff18f28fe66 to your computer and use it in GitHub Desktop.
Save hariedo/0c0a7f2bc72da70f53a6bff18f28fe66 to your computer and use it in GitHub Desktop.
public static Color HexRGB(uint hexcode)
{
// e.g., 0xFF0033
float b = (hexcode & 0xFF) / 255f;
float g = ((hexcode >> 8) & 0xFF) / 255f;
float r = ((hexcode >> 16) & 0xFF) / 255f;
return new Color(r, g, b);
}
public static Color HexRGBA(uint hexcode)
{
// e.g., 0xFF003380
float a = (hexcode & 0xFF) / 255f;
float b = ((hexcode >> 8) & 0xFF) / 255f;
float g = ((hexcode >> 16) & 0xFF) / 255f;
float r = ((hexcode >> 24) & 0xFF) / 255f;
return new Color(r, g, b, a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment