write a program to find out number of on bits in a number?
Answer Posted / kavitha
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 ? | 0 Yes | 1 No |
Post New Answer View All Answers
What is an arrays?
Find duplicates in a file containing 6 digit number (like uid) in O (n) time.
The __________ attribute is used to announce variables based on definitions of columns in a table?
Explain how can I pad a string to a known length?
Calculate the weighted average of a list of n numbers using the formula xavg = f1x1+f2x2+ ….+ fnxn where the f’s are fractional weighting factors, i.e., 0<=fi<1, and f1+f2+….+fn = 1
Which is best book for data structures in c?
Why do we use null pointer?
How do c compilers work?
What is the purpose of void in c?
What is the correct code to have following output in c using nested for loop?
What is function in c with example?
What is the difference between the local variable and global variable in c?
What is scope rule in c?
What is getch () for?
what is diffrence between linear and binary search in array respect to operators?what kind of operator can be used in both seach methods?