write a program to find out number of on bits in a number?
Answer Posted / vivek
int setbit=1; //Lets start checking from first bit
int numBitSet=0; //Number of bits set in the number
while(setbit>0)
{
if(number&setbit) //bit wise and
numBitSet++;
setbit=setbit<<1;
}
| Is This Answer Correct ? | 23 Yes | 12 No |
Post New Answer View All Answers
Write a c program to build a heap method using Pointer to function and pointer to structure ?
Should I learn c before c++?
Which is better malloc or calloc?
What is function pointer c?
What is 2c dna?
Why functions are used in c?
Here is a neat trick for checking whether two strings are equal
How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same
Write a program to check armstrong number in c?
Which one would you prefer - a macro or a function?
What is difference between far and near pointers?
Explain how can you tell whether a program was compiled using c versus c++?
What is a good way to implement complex numbers in c?
How do you convert strings to numbers in C?
Why is structure padding done in c?