Skip to content

Instantly share code, notes, and snippets.

@cacharle
Created August 28, 2019 13:15
Show Gist options
  • Save cacharle/b3cb4a0ff7725e176aafe46a483eef30 to your computer and use it in GitHub Desktop.
Save cacharle/b3cb4a0ff7725e176aafe46a483eef30 to your computer and use it in GitHub Desktop.
#include <stdio.h>
union Color
{
int hexcode;
struct
{
unsigned char b;
unsigned char g;
unsigned char r;
} rgb_s;
unsigned char rgb[3];
};
int main(void)
{
union Color c;
c.hexcode = 0xfe4abb;
printf("hexcode: %06x\n", c.hexcode);
printf("rgb: %02x %02x %02x\n", c.rgb[2], c.rgb[1], c.rgb[0]);
printf("rgb_s: %02x %02x %02x\n", c.rgb_s.r, c.rgb_s.g, c.rgb_s.b);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment