blob: a854158b18edc365fad652266cf837725e012bf9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
union pixel {
struct c {
unsigned r : 5;
unsigned g : 6;
unsigned b : 5;
} c;
uint16_t val;
};
union pixel p = {.c.r = 0x1b, .c.g = 0x4, .c.b = 0xa};
printf("%.4" PRIx16 " == %" PRIx16 "\n", p.val, 0x1b | 0x4 << 5 | 0xa << 11);
}
|