how do u find out the number of 1's in the binary
representation of a decimal number without converting it
into binary(i mean without dividing by 2 and finding out
the remainder)? three lines of c code s there it
seems...can anyone help

Answer Posted / barun

int x =0x1;
static count;
while(no ! =0)
{
if((no >>1 & x) ==1)
count+=1;
}
printf("%d",count);

Is This Answer Correct ?    7 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

in ‘C’ language for Matrix Multiplication fails” Introspect the causes for its failure and write down the possible reasons for its failure.

7799


Where are c variables stored in memory?

832


What is the difference between memcpy and memmove?

796


What is equivalent to ++i+++j?

880


Explain what are global variables and explain how do you declare them?

864


Explain how can type-insensitive macros be created?

802


a=10;b= 5;c=3;d=3; if(a printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d);

882


Explain the red-black trees?

843


Should a function contain a return statement if it does not return a value?

852


What is structure in c definition?

812


Can we access the array using a pointer in c language?

841


What are nested functions in c?

805


Explain what’s a signal? Explain what do I use signals for?

820


Can we declare variable anywhere in c?

754


I was asked to write a program in c which when executed displays how many no.of clients are connected to the server.

2138