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
What are types of preprocessor in c?
Why is #define used?
What is a pointer value and address in c?
C program to find all possible outcomes of a dice?
What are data types in c language?
What does != Mean in c?
What are the application of void data type in c?
What are the two forms of #include directive?
How to write a code for reverse of string without using string functions?
write a program to find the given number is prime or not
Why is C language being considered a middle level language?
how many types of operators are include in c language a) 4 b) 6 c) 8 d) 12
Explain what will be the outcome of the following conditional statement if the value of variable s is 10?
What is console in c language?
Write the test cases for checking a variable having value in range -10.0 to +10.0?