title: Convert integer to binary in python and compare the bits
body: <p>How to convert a int <code>n</code> into binary and test each bit of the resulting binary number?</p>
  
  <p>I have just got the following after a lot of googling:</p>
  
  <pre><code>def check_bit_positions(n, p1, p2):
      print int(str(n),2)
  </code></pre>
  
  <p>However i get an error <code>invalid literal for int() with base 2</code>. Let me know how can i get binary form of the input number and test each bit at position <code>p1</code> and <code>p2</code></p>
  
  <p>EDIT:</p>
  
  <pre><code>binary = '{0:b}'.format(n)
  if list(binary)[p1] == list(binary)[p2]:
       print "true"
   else:
       print "false"
  </code></pre>
  
  <p>The above code works now, however how can i check for postions p1 and p2 from the end of the list?</p>