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

  1. #include "timer1.h"
  2. char c = 'c';
  3. DO_IEXPR("Bit Count V4")    bitcnt(c)    OD
  4. }
  5.  
  6.  
  7. /*    bitcnt - return the bit sum of a byte argument
  8.  *    version 4
  9.  */
  10. #define BYTEMASK 0377
  11. int bitcnt(c)
  12.     register char c;
  13.     {
  14.     register int b;
  15.     register unsigned uc;
  16.  
  17.     uc = c & BYTEMASK;
  18.     b = 0;
  19.     while (uc != 0)
  20.         {
  21.         b++;
  22.         uc &= uc - 1;
  23.         }
  24.     return b;
  25.     }
  26.