Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- typedef struct {
- unsigned b0: 8, b1: 8, b2: 8, b3: 8;
- } word_bytes;
- typedef struct{
- unsigned b0: 1, b1: 1, b2: 1, b3: 1, b4: 1, b5: 1, b6: 1, b7: 1, b8: 1, b9: 1, b10: 1, b11: 1, b12: 1, b13: 1, b14: 1, b: 15, b16: 1, b17: 1, b18: 1, b19: 1, b20: 1, b21: 1, b22: 1, b23: 1, b24: 1, b25: 1, b26: 1, b27: 1, b28: 1, b29: 1, b30: 1, b31: 1;
- } word_bits;
- typedef union {
- int i;
- word_bits bit;
- word_bytes bytes;
- } word;
- int main()
- {
- // sets all bits to 0
- word w = {0};
- // turing on bits
- w.bit.b8 = 1;
- w.bit.b12 = 1;
- // first 8 bits
- w.bytes.b0 = 'a';
- // third 8 bits
- w.bytes.b2 = 'A';
- // fourth 8 bits
- w.bytes.b3 = 12;
- printf("w.i = %d\n", w.i);
- printf("w.b2 = %d %c\n", w.bytes.b2, w.bytes.b2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement