title: Reversing bits of Python integer
body: <p>Given a decimal integer (eg. 65), how does one reverse the underlying bits in Python? i.e.. the following operation:</p>
  <pre><code>65 → 01000001 → 10000010 → 130
  </code></pre>
  <p>It seems that this task can be broken down into three steps:</p>
  <ol>
  <li>Convert the decimal integer to binary representation</li>
  <li>Reverse the bits</li>
  <li>Convert back to decimal</li>
  </ol>
  <p>Steps #2 and 3 seem pretty straightforward (see <a href="https://stackoverflow.com/questions/5333509/how-do-you-reverse-the-significant-bits-of-an-integer-in-python">this</a> and <a href="https://stackoverflow.com/questions/746171/best-algorithm-for-bit-reversal-from-msb-lsb-to-lsb-msb-in-c">this</a> SO question related to step #2), but I'm stuck on step #1. The issue with step #1 is retrieving the full decimal representation with filling zeros (ie. 65 = 01000001, not 1000001).</p>
  <p>I've searched around, but I can't seem to find anything.</p>