Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What are types of preprocessor in c?

1112


Why is #define used?

1332


What is a pointer value and address in c?

1181


C program to find all possible outcomes of a dice?

2410


What are data types in c language?

1109


What does != Mean in c?

1093


What are the application of void data type in c?

1231


What are the two forms of #include directive?

1218


How to write a code for reverse of string without using string functions?

2200


write a program to find the given number is prime or not

4841


Why is C language being considered a middle level language?

1208


how many types of operators are include in c language a) 4 b) 6 c) 8 d) 12

1133


Explain what will be the outcome of the following conditional statement if the value of variable s is 10?

1326


What is console in c language?

1139


Write the test cases for checking a variable having value in range -10.0 to +10.0?

2367