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;
  }

2 comments:

  1. This page certainly has all of the info I wanted concerning this subject
    and didn't know who to ask.

    my website: Best cccamserver

    ReplyDelete
  2. The solutions to the first 25 questions of these puzzles are available at: http://codeitdown.com/c-puzzles-answered/.

    ReplyDelete

Your answer for the question

Related Posts Plugin for WordPress, Blogger...