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...


Give a method to count the number of ones in a 32 bit number?

Answers were Sorted based on User's Feedback



Give a method to count the number of ones in a 32 bit number?..

Answer / ataraxic

int i = 0;

while (x) {
x &= x-1;
++i;
};

printf("number of ones is %d\n", i);

Is This Answer Correct ?    1 Yes 0 No

Give a method to count the number of ones in a 32 bit number?..

Answer / 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

Give a method to count the number of ones in a 32 bit number?..

Answer / jayaprakash

#include<stdio.h>
#include<conio.h>

main()
{
int i;
int n;
int count=0;
int j;
int res=0;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
for(j=15;j>=0;j--)
{ i=1;
i=i<<j;
res=i&n;
if(res!=0)
count++;
}
printf("\nNumber of ones is:%d",count);


getch();

}

Is This Answer Correct ?    0 Yes 0 No

Give a method to count the number of ones in a 32 bit number?..

Answer / jayaprakash

#include<stdio.h>
#include<conio.h>

main()
{
int i;
int n;
int count=0;
int j;
int res=0;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
for(j=15;j>=0;j--)
{ i=1;
i=i<<j;
res=i&n;
if(res!=0)
count++;
}
printf("\nNumber of ones is:%d",count);


getch();

}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

what is C?

9 Answers   Syntel,


two progs are given. one starts counting frm 0 to MAX and the other stars frm MAX to 0. which one executes fast.

5 Answers   Verifone,


Explain what are binary trees?

0 Answers  


What is a macro, and explain how do you use it?

0 Answers  


What are the features of the c language?

0 Answers  


how to convert binary to decimal and decimal to binary in C lanaguage

7 Answers   BPO, Far East Promotions, IBM, RBS,


who is the editor of 'pokemon'?

1 Answers  


What is a structure in c language. how to initialise a structure in c?

0 Answers  


the maximum width of a c variable name can be a) 6 characters b) 8 characters c) 10 characters d) 20 characters

2 Answers  


Explain the use of 'auto' keyword in c programming?

0 Answers  


Find if a number is power of two or not?

1 Answers  


write the function int countchtr(char string[],int ch);which returns the number of timesthe character ch appears in the string. for example the call countchtr("she lives in Newyork",'e') would return 3.

6 Answers  


Categories