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   SiteMap shows list of All Categories in this site.
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 ?    1 Yes 2 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 ?    2 Yes 2 No
Venkat1435
 
 
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
write a code for large nos multilication (upto 200 digits) Persistent1
HOW DO YOU HANDLE EXCEPTIONS IN C? AppLabs2
Implement a function that returns the 5th element from the end in a singly linked list of integers in one pass. Microsoft2
What is the difference between null pointer and the void pointer?  2
define function Assurgent4
which types of data structure will i use to convert infix to post fix??? IIT2
write a program to find the number of even integers and odd integers in a given array in c language Olive-Tech2
1,4,8,13,21,30,36,45,54,63,73,?,?. Franklin-Templeton3
15.what is the disadvantage of using macros? 16.what is the self-referential structure? 17.can a union be self-referenced? 18.What is a pointer? 19.What is the Lvalue and Rvalue? 20.what is the difference between these initializations? 21.Char a[]=”string”; 22.Char *p=”literal”; 23.Does *p++ increment p, or what it points to?  1
main() { printf(5+"Vidyarthi Computers"); }  5
What is the result main() { char c=-64; int i=-32 unsigned int u =-16; if(c>i){ printf("pass1,"); if(c<u) printf("pass2"); else printf("Fail2");} else printf("Fail1); if(i<u) printf("pass2"); else printf("Fail2") } a)Pass1,Pass2 b)Pass1,Fail2 c)Fail1,Pass2 d)Fail1,Fail2 e)none IBM7
what is difference between array of characters and string Accenture8
main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2); } CitiGroup3
Can you think of a way when a program crashed before reaching main? If yes how?  2
what is a headerfile?and what will be a program without it explain nan example? Assurgent2
9.how do you write a function that takes a variable number of arguments? What is the prototype of printf () function? 10.How do you access command-line arguments? 11.what does ‘#include<stdio.h>’ mean? 12.what is the difference between #include<> and #include”…”? 13.what are # pragma staments? 14.what is the most appropriate way to write a multi-statement macro? L&T4
#define min((a),(b)) ((a)<(b))?(a):(b) main() { int i=0,a[20],*ptr; ptr=a; while(min(ptr++,&a[9])<&a[8]) i=i+1; printf("i=%d\n",i);}  2
What are the phases in s/w developed life cycle? wat is the diff b/w stack & queue...where do we use stack  5
How can I call a function, given its name as a string? ABC-Telecom1
how to implement stack work as a queue?  2
 
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