title: Count number of bits in an unsigned integer
body: <p>I want to write a function named <code>bitCount()</code> in the file: <code>bitcount.c</code> that returns the number of bits in the binary representation of its unsigned integer argument. </p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int bitCount (unsigned int n);
  
  int main () {
      printf ("# 1-bits in base 2 representation of %u = %d, should be 0\n",
          0, bitCount (0));
      printf ("# 1-bits in base 2 representation of %u = %d, should be 1\n",
          1, bitCount (1));
      printf ("# 1-bits in base 2 representation of %u = %d, should be 16\n",
          2863311530u, bitCount (2863311530u));
      printf ("# 1-bits in base 2 representation of %u = %d, should be 1\n",
          536870912, bitCount (536870912));
      printf ("# 1-bits in base 2 representation of %u = %d, should be 32\n",
          4294967295u, bitCount (4294967295u));
      return 0;
  }
  
  int bitCount (unsigned int n) {
      /* your code here */
  }
  </code></pre>
  
  <p>Okay, when I just run this I get:</p>
  
  <pre><code># 1-bits in base 2 representation of 0 = 1, should be 0
  # 1-bits in base 2 representation of 1 = 56, should be 1
  # 1-bits in base 2 representation of 2863311530 = 57, should be 16
  # 1-bits in base 2 representation of 536870912 = 67, should be 1
  # 1-bits in base 2 representation of 4294967295 = 65, should be 32
  
  RUN SUCCESSFUL (total time: 14ms)
  </code></pre>
  
  <p>It doesn't return the correct numbers of bits.</p>
  
  <p>What's the best way to return the number of bits in the binary representation of its unsigned integer argument in C?</p>