title: C program to find required number of bits for a given number
body: <p>I am new at programming and trying to understand the following program.</p>
  
  <p>This program gets the minimum number of bits needed to store an integer as a number.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  /*function declaration
  * name      : countBit
  * Desc      : to get bits to store an int number
  * Parameter : int 
  * return    : int 
  */
  int countBit(int);
  int main()
  {
     int num;
     printf("Enter an integer number :");
     scanf("%d",&amp;num);
  
     printf("Total number of bits required = %d\n",countBit(num));
     return 0;
  }
  
  int countBit(int n)
  {
     int count=0,i;
     if(n==0) return 0;
     for(i=0; i&lt; 32; i++)
     {    
        if( (1 &lt;&lt; i) &amp; n)
           count=i;
     }
  
     return ++count;
  }
  </code></pre>
  
  <p>Can you please explain how the <code>if( (1 &lt;&lt; i) &amp; n)</code> condition works?</p>