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

  1. #include "timer1.h"
  2. char c = 15;
  3. DO_IEXPR("Bit Count V5")    bitcnt(c)    OD
  4. }
  5.  
  6. /*
  7.  *    precomputed bit sum values
  8.  */
  9.  
  10. #define BYTEMASK 0377
  11.  
  12. char bitsum[256] = {
  13.     1, 0, 1, 1, 2, 1, 0, 1, 1, 2, 1, 
  14.     1, 0, 1, 1, 2, 1, 0, 1, 1, 2, 1, 
  15.     1, 0, 1, 1, 2, 1, 0, 1, 1, 2, 1, 
  16.     1, 0, 1, 1, 2, 1, 0, 1, 1, 2, 1, 
  17.     1, 0, 1, 1, 2, 1, 0, 1, 1, 2, 1, 
  18.     1, 0, 1, 1, 2, 1, 0, 1, 1, 2, 1, 
  19.     1, 0, 1, 1, 2, 1, 0, 1, 1, 2, 1, 
  20.     1, 0, 1, 1, 2, 1, 0, 1, 1, 2, 1, 
  21.     1, 0, 1, 1, 2, 1, 0, 1, 1, 2, 1, 
  22.     1, 0, 1, 1, 2, 1, 0, 1, 1, 2, 1, 
  23.     1, 0, 1, 1, 2, 1, 0, 1, 1, 2, 1, 
  24.     1, 0, 1, 1, 2, 1, 0, 1, 1, 2, 1, 
  25.     1, 0, 1, 1, 2, 1, 0, 1, 1, 2, 1,
  26.     1, 0, 1, 1, 2, 1, 0, 1, 1, 2, 1,
  27.     1, 0, 1, 1, 2, 1, 0, 1, 1, 2, 1,
  28.     1, 0, 1, 1, 2, 1, 0, 1, 1, 2, 1,
  29.     1, 0, 1, 1, 2, 1, 0, 1, 1, 2, 1,
  30.     1, 0, 1, 1, 2, 1, 0, 1, 1, 2, 1,
  31.     1, 0, 1, 1, 2, 1, 0, 1, 1, 2, 1
  32.     /* note - phoney values just for timing */
  33. };
  34.  
  35. /*
  36.  *    return the bit sum of a byte argument
  37.  *    version 5
  38.  */
  39.  
  40. int bitcnt(c)
  41. char c;
  42. {
  43.     extern char bitsum[256];
  44.  
  45.     return (bitsum[c & BYTEMASK]);
  46. }
  47.