Give a method to count the number of ones in a 32 bit number?

Answer Posted / ataraxic

int i = 0;

while (x) {
x &= x-1;
++i;
};

printf("number of ones is %d\n", i);

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is a function method?give example?

1918


Explain union.

641


What is getch () for?

681


What are the advantages of external class?

598


Why do we use c for the speed of light?

610






How many parameters should a function have?

670


Write a program to find the biggest number of three numbers in c?

590


Is it valid to address one element beyond the end of an array?

677


1) There is a singing competition for children going to be conducted at a local club. Parents have been asked to arrive at least an hour before and register their children’s names with the Program Manager. Whenever a participant registers, the Program Manager has to position the name of the person in a list in alphabet order. Write a program to help the Program Manager do this by placing the name in the right place each time the Program Manger enters a name. 2) the Event Manager has to send participants to the stage to perform in the order in which they registered. Write a program that will help the Event Manager know who to call to the stage to perform. The Logic should be in Data Structures

2747


What is the significance of c program algorithms?

685


What is adt in c programming?

615


what is reason of your company position's in india no. 1.

1779


Explain what is gets() function?

639


How can I read/write structures from/to data files?

556


in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above

637