title: How to count the number of ones in a byte without a loop in c?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/109023/best-algorithm-to-count-the-number-of-set-bits-in-a-32-bit-integer">Best algorithm to count the number of set bits in a 32-bit integer?</a>  </p>
  </blockquote>
  
  
  
  <p>Hello,</p>
  
  <p>Is there a more compact way of counting the number of ones in a byte without using a loop? I don't want to do the following if I don't have to. Thanks.</p>
  
  <pre><code>char myValue = 0x0F;
  
  int counter = 0;
  
  while (myValue &gt; 0)
  {
   if (myValue &amp; 0x01)
   {
    counter ++;
   }
  
   myValue = myValue &gt;&gt; 1;
  }
  </code></pre>