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
Do you have any idea how to compare array with pointer in c?
general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only
i got 75% in all semester am i eligible for your company
Write a simple code fragment that will check if a number is positive or negative.
Who developed c language and when?
What is the difference between fread buffer() and fwrite buffer()?
What are register variables in c?
What is void main () in c?
What is type qualifiers?
If I have a char * variable pointing to the name of a function ..
What is the difference between variable declaration and variable definition in c?
Do you know pointer in c?
What is malloc() function?
I have written a pro*C program to fetch data from the cursor. where in i have used the concept of BULK FETCH.... each FETCH statement is taking lots of time to fetch specified number of rows at...
How do you sort filenames in a directory?