write a program to find out number of on bits in a number?

Answer Posted / kavitha

int setbit=1; //Lets start checking from first bit
int numBitSet=0; //Number of bits set in the number

while(setbit>0)
{

if(number&setbit) //bit wise and
numBitSet++;

setbit=setbit<<1;
}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the right way to use errno?

625


what is the height of tree if leaf node is at level 3. please explain

1604


Why is extern used in c?

614


Explain main function in c?

630


What is typedef?

681






Why main function is special give two reasons?

953


Why dont c comments nest?

625


Given a valid 24 hour format time find the combination of the value and write a program ,do not hard the value and if any other inputs provided should work with the logic implemented Input: 11:30 Output: 13:10 Input: 18:25 Output: 21:58

1123


What is the difference between int main and void main?

578


What is floating point constants?

695


What is the ANSI C Standard?

782


How do we make a global variable accessible across files? Explain the extern keyword?

1424


What is pre-emptive data structure and explain it with example?

3214


What is a node in c?

552


How do I convert a string to all upper or lower case?

631