title: How can I convert a 256-bit big endian integer to little endian in Python?
body: <p>Not too complicated, or so I would hope. I've got a 256-bit hexadecimal integer encoded as big endian that I need to convert to little endian. Python's struct module would usually suffice, but <a href="http://docs.python.org/2/library/struct.html" rel="nofollow">the official documentation</a> has no listed format with size even close to that which I need.</p>
  
  <p>Using struct's non length specific types (though I could be doing this wrong) doesn't appear to work:</p>
  
  <pre><code>&gt;&gt; x = 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000'
  &gt;&gt; y = struct.unpack('&gt;64s', x)[0] # Unpacking as big-endian
  &gt;&gt; z = struct.pack('&lt;64s', y) # Repacking as little-endian
  &gt;&gt; print z
  'ffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000'
  </code></pre>
  
  <p>Example code (what should happen):</p>
  
  <pre><code>&gt;&gt; x = 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000'
  &gt;&gt; y = endianSwap(x)
  &gt;&gt; print y
  '00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
  </code></pre>