home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 6 / FreshFish_September1994.bin / new / dev / c / hce / examples / clib / tests / fieldtest.c < prev    next >
C/C++ Source or Header  |  1992-09-02  |  1KB  |  52 lines

  1. /*
  2.  * HCC 32 bit int field test program by TetiSoft
  3.  * Notice that the fields are filled from right to left,
  4.  * which may differ from Aztec or Lattice.
  5.  */
  6.  
  7. /*
  8.  * Modified slightly by Jason Petty for HCE. (16/6/94)
  9.  * Changes marked VANSOFT.
  10.  */
  11.  
  12. union fieldtest
  13. {
  14.  int all;
  15.  struct {
  16.   int a:1;
  17.   int b:2;
  18.   int c:3;
  19.   int d:4;
  20.   int e:5;
  21.   int f:6;
  22.   int g:7;
  23.  } f;
  24. } test;
  25.  
  26. main()
  27. {
  28.  test.f.a=1; /* Bit      0 =                                1*/
  29.  test.f.b=2; /* Bits  2- 1 =                              10 */
  30.  test.f.c=5; /* Bits  5- 3 =                           101 */
  31.  test.f.d=6; /* Bits  9- 6 =                       0110 */
  32.  test.f.e=17; /* Bits 14-10 =                  10001  */
  33.  test.f.f=30; /* Bits 20-15 =            011110  */
  34.  test.f.g=65; /* Bits 27-21 =     1000001   */
  35.   /*  unused Bits 31-28 = 0000    */
  36.    /* all        = 00001000001011110100010110101101*/
  37.    /*            =$   0   8   2   F   4   5   A   D*/
  38.  
  39. /* Changed lines below slightly. VANSOFT. */
  40.  printf(
  41.    "\n\n\n32 bit integer fields test for the internal compiler 'HCC'.\n\n");
  42.  
  43.  printf("%d %d %d %d %d %d %d - Extracted from bit field $%08x\n\n",
  44.         test.f.a, test.f.b, test.f.c, test.f.d, test.f.e,
  45.         test.f.f, test.f.g, test.all);
  46.  
  47.  printf("The correct result should be:\n");
  48.  printf("1 2 5 6 17 30 65 - Extracted from bit field $082F45AD\n\n");
  49.  printf("See source code for how it works...\n\n\n");
  50. }
  51.  
  52.