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

What is difference between main and void main?

630


What does it mean when the linker says that _end is undefined?

635


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

1907


What is null pointer constant?

595


When is a void pointer used?

678






A float occupies 4 bytes in memory. How many bits are used to store exponent part? since we can have up to 38 number for exponent so 2 ki power 6 6, 6 bits will be used. If 6 bits are used why do not we have up to 64 numbers in exponent?

1777


Explain what does it mean when a pointer is used in an if statement?

617


Difference between exit() and _exit() function?

657


What is difference between far and near pointers?

612


What is a pointer in c?

683


how to capitalise first letter of each word in a given string?

1434


What is modifier & how many types of modifiers available in c?

612


Explain 'bus error'?

563


Is it better to use a macro or a function?

657


What are the key features in c programming language?

617