summaryrefslogtreecommitdiffstats
path: root/c/bit_compose.c
blob: bd250db5f112c82de734d4c73d1664dd95e91ca6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdint.h>
#include <stdio.h>

typedef union __attribute__ ((__packed__))
{
    struct __attribute__ ((__packed__))
    {
        unsigned int table_id      : 11;
        unsigned int int_table_id  : 11;
        unsigned int entry_id      : 12;
        unsigned int generation    : 30;
    };
    uintptr_t i;
} BITS;

uintptr_t compose(uintptr_t a, uintptr_t b, uintptr_t c, uintptr_t d)
{
    BITS i;
    i.table_id = a;
    i.int_table_id = b;
    i.entry_id = c;
    i.generation = d;
    return i.i;
}

int main(int argc, char **argv, char **env)
{
    uintptr_t t = compose(666,777,888,999);
    printf("%d %d %d %d -> 0x%lu\n", 666, 777, 888, 999, t);

    return 0;
}