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

Answer Posted / vivek

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 ?    23 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Are the variables argc and argv are local to main?

973


What does char * * argv mean in c?

797


Describe wild pointers in c?

828


What does emoji p mean?

775


Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it's a simple test.]

823


Describe how arrays can be passed to a user defined function

990


What is sizeof int in c?

806


What are qualifiers in c?

763


write a c program in such a way that if we enter the today date the output should be next day's date.

1899


process by which one bit patten in to another by bit wise operation is? (a) masking, (b) pruning, (c) biting, (d) chopping,

2129


what is the diffrenet bettwen HTTP and internet protocol

1578


What is the scope of static variable in c?

710


Explain About fork()?

837


How to draw the flowchart for structure programs?

8958


What are Macros? What are its advantages and disadvantages?

850