title: Comparing bit representation of objects in Python
body: <p>I am watching a video named <a href="https://youtu.be/C4Kc8xzcA68?t=166" rel="nofollow noreferrer">The Mighty Dictionary</a> which has the following code:</p>
  <pre><code>k1 = bits(hash('Monty'))
  k2 = bits(hash('Money'))
  diff = ('^' [a==b] for a,b in zip(k1,k2))
  print(k1,k2,''.join(diff))
  </code></pre>
  <p>As I understand, <code>bits</code> is not a built-in method in Python, but his own written method which is similar to `format(x, 'b'), or is it something that existed in Python 2? (I've never wrote code in Python 2)</p>
  <p>I've tried to accomplish the same, get the bits representation of the strings and check where the bits differ:</p>
  <pre><code>k1 = format(hash('Monty'),'b')
  k2 = format(hash('Money'),'b')
  diff = ('^ ' [a==b] for a,b in zip(k1,k2))
  print(k1,'\n',k2,'\n',''.join(diff))
  </code></pre>
  <p>I do get the expected result:</p>
  <p><strong>UPDATED</strong>
  Had to shift the first line by 1 space to match the symbols</p>
  <pre><code> 110111010100001110100101100000100110111111110001001101111000110 
   -1000001111101001011101001010101101000111001011011000011110100 
   ^  ^^^  ^ ^^ ^^^   ^^^^^^^ ^ ^^^^^  ^^   ^^  ^^^^^^^ ^   ^ ^^^
  </code></pre>
  <p>Also, the lengths of the bits are not the same, whereas I understand that no matter the string, it will take the same, in my case, 64 bits? But its 63 and 62.</p>
  <pre><code>print(len(format(hash('Monty'),'b')))
  print(len(format(hash('Money'),'b')))
  
  63
  62
  </code></pre>
  <p>So, to sum up my question:</p>
  <ol>
  <li>Is <code>bits</code> a built-in method in Python2?</li>
  <li>Is the recommended way to compare bit representation of an object is using the following:</li>
  </ol>
  <pre><code>def fn():
      pass
  
  print(format(hash(fn),'b'))
  # -111111111111111111111111111111111101111000110001011100000000101
  </code></pre>
  <ol start="3">
  <li>Shouldn't all objects have the same length of bits that represent the object depending on the processor? If I run the following code several times I get these results:</li>
  </ol>
  <pre><code>def fn():
      pass
  
  def nf():
      pass
  
  print(format(hash(fn),'b'))
  print(format(hash(nf),'b'))
  
  # first time
  # 10001001010011010111110000100
  # -111111111111111111111111111111111101110110101100101000001000001
  
  # second time
  # 10001001010011010111111101010
  # 10001001010011010111110000100
  
  # third time
  # 10001001010011010111101010001
  # -111111111111111111111111111111111101110110101100101000001000001
  </code></pre>