title: How to set bit and print all bits in number using C
body: <p>I have following function to print bits:</p>
  
  <pre><code>void printBits(unsigned int num)
  {
     for(int bit=0;bit&lt;(sizeof(unsigned int) * 8); bit++)
     {
        printf("%i ", num &amp; 0x01);
        num = num &gt;&gt; 1;
     }
  }
  </code></pre>
  
  <p>and I want to set bit number 5 as follow:</p>
  
  <pre><code>unsigned int DataInMemory = 0x00000000;
  DataInMemory |= (1&lt;&lt;5);
  </code></pre>
  
  <p>the result of printBites function is:</p>
  
  <blockquote>
    <p>0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</p>
  </blockquote>
  
  <p>it means that <code>1 &lt;&lt; 5</code> set bit 6 not bit 5. Is it difference between bit position (indexes) and bit in programming nomenclature?
  How to set bit and print all bits in number using C?</p>