diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2017-02-21 12:04:57 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2017-02-21 12:04:57 +0100 |
commit | 260131c35f7f1b68b66e5b29916ec05a38c4ca56 (patch) | |
tree | e00a2df2f76475ceaf56e9fbdb49757d4159c763 /c/bit_compose.c | |
parent | c3892aedf180a9fbc0742f5e1829346985c4a6b0 (diff) | |
download | share-260131c35f7f1b68b66e5b29916ec05a38c4ca56.zip share-260131c35f7f1b68b66e5b29916ec05a38c4ca56.tar.gz |
c : add bit_array, bit_compose, malloc_hook
Diffstat (limited to 'c/bit_compose.c')
-rw-r--r-- | c/bit_compose.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/c/bit_compose.c b/c/bit_compose.c new file mode 100644 index 0000000..bd250db --- /dev/null +++ b/c/bit_compose.c @@ -0,0 +1,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; +} |