Advertisement
BenTibnam

6 bit union representing cards

Nov 21st, 2023
571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. // 6 bit structure
  4. typedef struct pcard
  5. {
  6.     // don't need negative representation
  7.     unsigned pips: 4;   // 4 bits = 0 - 15
  8.     unsigned suits: 2;  // 2 bits = 0 - 3
  9. } pcard;
  10.  
  11. int main()
  12. {
  13.     pcard c;
  14.    
  15.     /***
  16.      * Suits numerical values
  17.      * 0 - hearts
  18.      * 1 - clubs
  19.      * 2 - spades
  20.      * 3 - diamonds
  21.      ***/
  22.     c.pips = 9;
  23.     c.suits = 2;
  24.    
  25.     printf("Card pip: %d\n", c.pips);
  26.     printf("Card suits: %d\n", c.suits);
  27. }
Tags: unions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement