C Puzzle #14


Here is yet another implementation of CountBits. Verify whether it is correct (how do you that???). If so, find out the logic used.
int CountBits(unsigned int x)
  {
      int count=0;
      while(x)
      {
          count++;
          x = x&(x-1);
      }
      return count;
  }
Related Posts Plugin for WordPress, Blogger...