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

Answer Posted / vignesh1988i

#include<stdio.h>
#include<conio.h>
void main()
{
unsigned i;
int j=0,count=0;;
printf("Enter the number :");
scanf("%ld",&i);
while(j<=31)
{
if(!(((i>>j)&1)^1))
count++;
j++;
}
printf("\nnumber of 1's in ur number is : %d",count);
getch();
}


thank u

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How is a null pointer different from a dangling pointer?

547


write a program that types this pattern: 12345678987654321 12345678 87654321 1234567 7654321 123456 654321 12345 54321 1234 4321 123 321 12 21 1 1

3252


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create.

1466


Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..

638


What is the difference between variable declaration and variable definition in c?

550






what do you mean by inline function in C?

605


What is data types?

624


how to execute a program using if else condition and the output should enter number and the number is odd only...

1645


What is dynamic variable in c?

551


Explain about the constants which help in debugging?

839


Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?

659


the portion of a computer program within which the definition of the variable remains unchanged a) mode b) module c) scope d) none

637


How does normalization of huge pointer works?

617


Write a program to know whether the input number is an armstrong number.

660


What is an auto variable in c?

740