Cant decode hex sting into decimal. Getting TypeError.

0 votes
I am trying to decode a lenghty hex string into a decimal value. I have tried online decoders for this. Now i want to use python to decode it. I have written the code but it shows TypeError. What have i done wrong?

hex string: 0x00000000000000000000000000000000000000000000000bf97e2a21966df7fe

expected decoded result: 220892037897060743166


TypeError                                 Traceback (most recent call last)
<ipython-input-32-1cf86ff46cbc> in <module>()
      9 key=keyarr[0]
---> 11 "0x00000000000000000000000000000000000000000000000bf97e2a21966df7fe".decode("hex")

/usr/local/Cellar/python/2.7.13_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/ in hex_decode(input, errors)
     40     """
     41     assert errors == 'strict'
---> 42     output = binascii.a2b_hex(input)
     43     return (output, len(input))

TypeError: Non-hexadecimal digit found

I am not understanding where i went wrong. Please help me out
Jul 6, 2018 in Blockchain by digger
• 26,660 points

1 answer to this question.

0 votes
On the line where it shows error, you have used .decode("hex"). It means you are treating the string as hex data.
To get the proper result call int with a base 16, like this: int(your_string, base=16)

Output using python 3.6.1:

>>> a = '0x00000000000000000000000000000000000000000000000bf97e2a21966df7fe'
>>> a
>>> int(a, 16)
answered Jul 6, 2018 by slayer
• 29,270 points

Related Questions In Blockchain

0 votes
1 answer

Cant Decode Bitcoin Base58 address to byte array

In your for-loop: for (int k = b256.Length ...READ MORE

answered Aug 21, 2018 in Blockchain by digger
• 26,660 points
0 votes
1 answer

TypeError: argument must be a string node.js while encoding to hex string.

The error is in protobuf.Transaction.create headerSignature needs to be a string, ...READ MORE

answered Nov 6, 2018 in Blockchain by Omkar
• 69,000 points
+1 vote
1 answer

Getting issues while Sending signTransaction with web3.js

The chain ID for ropsten is 3. ...READ MORE

answered Mar 28, 2018 in Blockchain by Johnathon
• 9,090 points
0 votes
1 answer
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 26,660 points
+1 vote
1 answer
0 votes
1 answer

Getting error when i execute ./ -m up command.

The error is caused because you're trying ...READ MORE

answered Jul 12, 2018 in Blockchain by slayer
• 29,270 points
0 votes
1 answer

Can’t find value for key while using CouchDB for Fabric.

In the output you have mentioned: {   "id": ...READ MORE

answered Jul 31, 2018 in Blockchain by slayer
• 29,270 points