title: How to print binary number via printf
body: <blockquote>
    <p><strong>Possible Duplicate:</strong> <br/>
    <a href="https://stackoverflow.com/questions/111928/is-there-a-printf-converter-to-print-in-binary-format">Is there a printf converter to print in binary format?</a></p>
  </blockquote>
  
  
  
  <p>Here is my program</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int main ()
  {
      int i,a=2;
      i=~a;
      printf("a=%d\ni=%d\n",a,i);
  
      return 0;
  }
  </code></pre>
  
  <p>The output is</p>
  
  <pre><code>a=2
  i=-3
  </code></pre>
  
  <p>I want this to print in binary. There are %x, %o, and %d which are for hexadecimal, octal, and decimal number, but what is for printing binary in printf?</p>