Give a method to count the number of ones in a 32 bit number?
Answer Posted / vignesh1988i
#include<stdio.h>
#include<conio.h>
void main()
{
unsigned i;
int j=0,count=0;;
printf("Enter the number :");
scanf("%ld",&i);
while(j<=31)
{
if(!(((i>>j)&1)^1))
count++;
j++;
}
printf("\nnumber of 1's in ur number is : %d",count);
getch();
}
thank u
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
How can you determine the size of an allocated portion of memory?
What is struct node in c?
Why doesnt that code work?
Why do we need volatile in c?
Function which gives a pointer to a binary trees const an integer value at each code, return function of all the nodes in binary tree.?
What is switch in c?
What is chain pointer in c?
What is strcmp in c?
What is the difference between volatile and const volatile?
how can I convert a string to a number?
Can you mix old-style and new-style function syntax?
Write a program that takes a 5 digit number and calculates 2 power that number and prints it(should not use big integers and exponential functions)
Explain how can I open a file so that other programs can update it at the same time?
What are the 5 elements of structure?
What is ambagious result in C? explain with an example.