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

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