home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 161_01 / 102.c < prev    next >
C/C++ Source or Header  |  1985-08-29  |  503b  |  32 lines

  1. #include "timer1.h"
  2.     char c = 'c';
  3.     short j = 255;
  4.     short k = 7;
  5.  
  6.     DO_IEXPR("Bit Count V1")    bitcnt(c)    OD
  7.     DO_IEXPR("++k")            ++k              OD
  8.     k = 7;
  9.     DO_IEXPR("j >> k")        j >> k          OD
  10.     k = 255;
  11.     DO_IEXPR("j <= k")        j <= k          OD
  12.     DO_IEXPR("j & k")        j & k              OD
  13. }
  14.  
  15.  
  16. /*    bitcnt - return the bit sum of a byte argument
  17.  *    version 1
  18.  */
  19. #define CHAR_BIT 8
  20. int bitcnt(c)
  21.     char c;
  22.     {
  23.     int b;
  24.     int i;
  25.  
  26.     b = 0;
  27.     for (i = 0; i < CHAR_BIT; ++i)
  28.         if ((c >> i) & 01)
  29.             ++b;
  30.     return (b);
  31.     }
  32.