title: calculate number of bits set in byte
body: <p>I am interested, which is the optimal way of calculating the number of bits set in byte by this way</p>
  
  <pre><code>template&lt; unsigned char byte &gt; class BITS_SET
  {
  public:
      enum {
       B0 = (byte &amp; 0x01) ? 1:0,
       B1 = (byte &amp; 0x02) ? 1:0,
       B2 = (byte &amp; 0x04) ? 1:0,
       B3 = (byte &amp; 0x08) ? 1:0,
       B4 = (byte &amp; 0x10) ? 1:0,
       B5 = (byte &amp; 0x20) ? 1:0,
       B6 = (byte &amp; 0x40) ? 1:0,
       B7 = (byte &amp; 0x80) ? 1:0
      };
  public:
   enum{RESULT = B0+B1+B2+B3+B4+B5+B6+B7};
  };
  </code></pre>
  
  <p>Maybe it is optimal when value of byte is known at run-time? Is it recommended use this in code?</p>