What is the most efficient way to count the number of bits
which are set in a value?

Answer Posted / pappu kumar sharma

int fnCntbts(int num )
{
int iCnt = 0;
while ( num )
{
num &= (num-1) ;
iCnt++;
}

return iCnt;

}

Is This Answer Correct ?    11 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to compare array with pointer in c?

872


explain what is fifo?

868


What is %s and %d in c?

786


What is the best organizational structure?

904


the question is that what you have been doing all these periods (one year gap)

1886


What are loops c?

837


How to establish connection with oracle database software from c language?

1974


Is a house a mass structure?

884


how to find anagram without using string functions using only loops in c programming

2970


What is pragma in c?

878


What is the general form of a C program?

817


How can I invoke another program (a standalone executable, or an operating system command) from within a c program?

923


What is a stream water?

923


any function have arguments one or more OR not . it is compulsary a) any function compulsary have one or more arguments b) any function did not have arguments. It is not compulsary c) it is optional it is not compulsary d) none of the above

907


What does c mean in basketball?

804