write a program to find out number of on bits in a number?

Answer Posted / jaya j

unsigned int count1s(unsigned char x)
{
int p;
for(p=0;x!=0;x>>=1)
if(x&1)
p++;
return p;
}

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are local static variables?

620


Explain what are header files and explain what are its uses in c programming?

629


i want to switch my career from quailty assurance engineering to development kindly guide me from which programming language its better for me to start plz refer some courses or certifications too i have an experience of 1.5 yrs in QA field.Kindly guide me

1481


Can math operations be performed on a void pointer?

590


a value that does not change during program execution a) variabe b) argument c) parameter d) none

698






What is pass by reference in functions?

326


What is New modifiers?

672


What is %d called in c?

761


What are 'near' and 'far' pointers?

620


If i have an array 0 to 99 i.e,(Size 100) I place the values 1 to 100 randomly like a[0]=29,a[1]=56 upto array[99].. the values are only between 1 to 100. getting the array values by using scanf.. If i entered one wrong element value line a[56]=108. how can i find it.. and also how to find the missing value in 1 to 100.. and i want to replace the missing values.. any one of them know please post your answer..

1595


Do you know pointer in c?

594


What is the best way to comment out a section of code that contains comments?

784


How can a number be converted to a string?

608


What is the difference between the local variable and global variable in c?

533


Is there a built-in function in C that can be used for sorting data?

745