write a program to find out number of on bits in a number?
Answer Posted / naveen
//plz let me know whether it is correct or not...bcoz am just beginner
#include<stdio.h>
void main()
{
int j=0,i=0xFFFFE,temp=1;
int count=0;
while(j<=(sizeof(int)*8-1))
{
if(i&temp)
count++;
temp=temp<<1;
j++;
}
printf("%d",count);
}
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
Explain 'bit masking'?
How do I get a null pointer in my programs?
What is the most efficient way to store flag values?
Explain with the aid of an example why arrays of structures don’t provide an efficient representation when it comes to adding and deleting records internal to the array.
what will be the output for the following main() { printf("hi" "hello"); }
How can I insert or delete a line (or record) in the middle of a file?
What are file streams?
to print the salary of an employee according to follwing calculation: Allowances:HRA-20% of BASIC,DA-45% of BASIC,TA-10%. Deductions:EPF-8% of BASIC,LIC-Rs.200/-Prof.Tax:Rs.200/- create c language program?
How macro execution is faster than function ?
What is scanf_s in c?
How can I run c program?
in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above
string reverse using recursion
How can I list all of the predefined identifiers?
Explain null pointer.