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

pierrot's divisor program using c or c++ code

1719


What is int main () in c?

617


Can a variable be both static and volatile in c?

598


Explain what is output redirection?

657


What does printf does?

731






I just typed in this program, and it is acting strangely. Can you see anything wrong with it?

548


How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?

581


Explain what is the difference between functions getch() and getche()?

597


How can I automatically locate a programs configuration files in the same directory as the executable?

619


What does %p mean c?

617


If jack lies on Mon, Tue Wed and jill lies on Thursday, Friday and Saturday. If both together tell they lied yesterday. So c the given options and then c cos in the given dates one will be saying the truth and one will be lying. I got Thursday as option because jack is saying the truth he lied yest but jill is lying again as he lies on that day.

1780


Explain zero based addressing.

597


What are the basic data types associated with c?

805


Why we not create function inside function.

1740


How many bytes is a struct in c?

717