title: How to decode (very large in value) hex string into decimal?
body: <p>I was trying to decode hex strings similar to the following format: </p>
  
  <pre><code>0x00000000000000000000000000000000000000000000000bf97e2a21966df7fe
  </code></pre>
  
  <p>I was able to decode it with the <a href="http://www.rapidtables.com/convert/number/hex-to-decimal.htm" rel="nofollow noreferrer">online calculator</a>. The correct decoded number should be <code>220892037897060743166</code>.</p>
  
  <p>However, when I am trying to decode it with python with the following code, it returns error:</p>
  
  <pre><code>"0x00000000000000000000000000000000000000000000000bf97e2a21966df7fe".decode("hex")
  
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-32-1cf86ff46cbc&gt; in &lt;module&gt;()
        9 key=keyarr[0]
       10 
  ---&gt; 11 "0x00000000000000000000000000000000000000000000000bf97e2a21966df7fe".decode("hex")
  
  /usr/local/Cellar/python/2.7.13_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/hex_codec.py in hex_decode(input, errors)
       40     """
       41     assert errors == 'strict'
  ---&gt; 42     output = binascii.a2b_hex(input)
       43     return (output, len(input))
       44 
  
  TypeError: Non-hexadecimal digit found
  </code></pre>
  
  <p>Then I removed the 0x in the front of the hex number and tried again: </p>
  
  <pre><code>"00000000000000000000000000000000000000000000000bf97e2a21966df7fe".decode("hex")
  </code></pre>
  
  <p>Then the output became:</p>
  
  <pre><code>'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0b\xf9~*!\x96m\xf7\xfe'
  </code></pre>
  
  <p>I actually don't understand the output ...</p>
  
  <p>In case you are wondering where do those numbers come from, they are from <a href="https://ethereum.stackexchange.com/questions/23393/ethereum-token-divide-value-by-1018/23395">Ethereum blockchain (ERC20) tokens</a>. </p>