title: Rotate bits in python
body: <p>Out of curiosity, I was seeing what the operations to transform an object's id into its hash look like in the string domain, rather than using the usual bitwise operations like <code>^</code>, <code>|</code>, <code>&amp;</code>, <code>~</code>.</p>
  
  <pre><code>class A:
      pass
  
  def my_hash(a):
      bits = format(id(a), '064b')
      rot4 = bits[-4:] + bits[:-4]
      n = int(rot4, 2)
      return n
  
  for _ in xrange(10):
      a = A()
      print hash(a) == my_hash(a), hash(a), my_hash(a)
  </code></pre>
  
  <p>But as you can see below, the function below isn't correct some of the time.  What am I missing?</p>
  
  <pre><code>&gt;&gt;&gt; run /tmp/thing.py
  True 272331835 272331835
  False -9223372036582443978 9223372037127107638
  True 272331835 272331835
  False -9223372036582443978 9223372037127107638
  True 272331835 272331835
  False -9223372036582443978 9223372037127107638
  True 272331835 272331835
  False -9223372036582443978 9223372037127107638
  True 272331835 272331835
  False -9223372036582443978 9223372037127107638
  </code></pre>