home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / ctutor2.zip / BITFIELD.C < prev    next >
Text File  |  1989-11-10  |  1KB  |  47 lines

  1.                                          /* Chapter 11 - Program 7 */
  2. #include "stdio.h"
  3.  
  4. void main()
  5. {
  6. union {
  7.    int index;
  8.    struct {
  9.       unsigned int x : 1;
  10.       unsigned int y : 2;
  11.       unsigned int z : 2;
  12.    } bits;
  13. } number;
  14.  
  15.    for (number.index = 0;number.index < 20;number.index++) {
  16.       printf("index = %3d, bits = %3d%3d%3d\n",number.index,
  17.               number.bits.z,number.bits.y,number.bits.x);
  18.    }
  19. }
  20.  
  21.  
  22.  
  23. /* Result of execution
  24.  
  25. index =   0, bits =   0  0  0
  26. index =   1, bits =   0  0  1
  27. index =   2, bits =   0  1  0
  28. index =   3, bits =   0  1  1
  29. index =   4, bits =   0  2  0
  30. index =   5, bits =   0  2  1
  31. index =   6, bits =   0  3  0
  32. index =   7, bits =   0  3  1
  33. index =   8, bits =   1  0  0
  34. index =   9, bits =   1  0  1
  35. index =  10, bits =   1  1  0
  36. index =  11, bits =   1  1  1
  37. index =  12, bits =   1  2  0
  38. index =  13, bits =   1  2  1
  39. index =  14, bits =   1  3  0
  40. index =  15, bits =   1  3  1
  41. index =  16, bits =   2  0  0
  42. index =  17, bits =   2  0  1
  43. index =  18, bits =   2  1  0
  44. index =  19, bits =   2  1  1
  45.  
  46. */
  47.