ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
What is the most efficient way to count the number of bits
which are set in a value?
 Question Submitted By :: Tribhuvan Sharma
I also faced this Question!!     Rank Answer Posted By  
 
  Re: What is the most efficient way to count the number of bits which are set in a value?
Answer
# 1
pseudo

int size is 32 bits...right?

for(i = 0 to 31)
{
      count += (value & 1) //& = and oprator
      shift left value 
}
 
Is This Answer Correct ?    3 Yes 4 No
Boomer
 
  Re: What is the most efficient way to count the number of bits which are set in a value?
Answer
# 2
main()
{
int n,count=0; 
printf("enter a number");
scanf("%d",&n);//enterd no.is 5
while(n>0)
{
count++;
n=n&n-1;//binary of n is 101
        // binary of n-1 is 100
        //n&n-1 is (i.e 101 
                       &100 =100 )
                         
}
printf("%d",count);
getch();
}         output is 2(i.e 2 ones in 101)
 
Is This Answer Correct ?    14 Yes 2 No
Venkat1435
 
 
 
  Re: What is the most efficient way to count the number of bits which are set in a value?
Answer
# 3
int fnCntbts(int num )
{
 int iCnt = 0;
 while ( num )
 {
   num &= (num-1) ;
  iCnt++;
 } 

return iCnt;

}
 
Is This Answer Correct ?    2 Yes 0 No
Pappu Kumar Sharma
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
what are two categories of clint-server application development ?  1
two variables are added answer is stored on not for third variable how it is possible?  3
write a C code To reverse a linked list Motorola2
Is there any restriction in how many arguments printf or scanf function can take? in which file in my c++ compiler i can see the code for implementation of these two functions??  3
the format specified for hexa decimal is a.%d b.%o c.%x d.%u TCS4
write an algorithm to get a sentence and reverse it in the following format: input : I am here opuput: Here Am I note: first letter of every word is capiatlised  2
How the C program can be compiled? HP7
define function Assurgent4
int *a[5] refers to TCS8
write a program to insert an element at the specified position in the given array in c language IBM2
i want the code for printing the output as follows 4 4 3 3 2 2 1 1 0 1 1 2 2 3 3 4 4  1
which types of data structure will i use to convert infix to post fix??? IIT3
Is the following code legal? struct a { int x; struct a b; }  3
Why data types in all programming languages have some range? Why ritche have disigned first time likethat?Why not a single data type can support all other types? Excel1
what is array? HCL22
void main() { int i=5; printf("%d",i++ + ++i); } ME11
We can draw a box in cprogram by using only one printf();& without using graphic.h header file? NIIT3
Sir i want e-notes of C languge of BAlaguruswami book i.e scanned or pdf file of balaguruswamy book on c language.PLEASE SEND ME on my mail id ajit_kolhe@rediff.com  4
how to make c program without a libary? e.g.#include<stdio.h> libary is not in c progaram.  1
a 'c' program to tell that the set of three coordinates lie on a same line Persistent1
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com