title: How to get 0-padded binary representation of an integer in java?
body: <p>for example, for <code>1, 2, 128, 256</code> the output can be (16 digits):</p>
  
  <pre><code>0000000000000001
  0000000000000010
  0000000010000000
  0000000100000000
  </code></pre>
  
  <p>I tried</p>
  
  <pre><code>String.format("%16s", Integer.toBinaryString(1));
  </code></pre>
  
  <p>it puts spaces for left-padding:</p>
  
  <pre><code>`               1'
  </code></pre>
  
  <p>How to put <code>0</code>s for padding. I couldn't find it in <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.html#syntax" rel="noreferrer">Formatter</a>. Is there another way to do it?</p>
  
  <p>P.S. <a href="https://stackoverflow.com/questions/473282/left-padding-integers-with-zeros-in-java">this post</a> describes how to format integers with left 0-padding, but it is not for the binary representation.</p>