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 / jay
Well bitwise operators are one way to do it. But for
positive integers, I thought up another solution. I think
this could work for int n:
for(int i = 0, int count = 0; i < sizeOf(n) / 8.0; i++){
count += (n - 2^i > 0) ? 1 : 0;
}
Is that what you meant by 3 lines?
Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
Explain the red-black trees?
What are header files why are they important?
How to explain the final year project as a fresher please answer with sample project
Is c language still used?
What type is sizeof?
explain what are actual arguments?
What is the difference between int main and void main?
Calculate 1*2*3*____*n using recursive function??
How can I remove the leading spaces from a string?
Is it fine to write void main () or main () in c?
Why clrscr is used in c?
What is the scope of static variable in c?
How can you invoke another program from within a C program?
List at least 10 sorting methods indicating their average case complexity, worst case complexity and best case complexity.
How can a program be made to print the line number where an error occurs?