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

error:
"0x00000000000000000000000000000000000000000000000bf97e2a21966df7fe".decode("hex")

TypeError                                 Traceback (most recent call last)
<ipython-input-32-1cf86ff46cbc> in <module>()
      9 key=keyarr[0]
     10
---> 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'
---> 42     output = binascii.a2b_hex(input)
     43     return (output, len(input))
     44

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,740 points
4,412 views

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
'0x00000000000000000000000000000000000000000000000bf97e2a21966df7fe'
>>> int(a, 16)
220892037897060743166
answered Jul 6, 2018 by slayer
• 29,350 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,740 points
1,000 views
0 votes
2 answers
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,210 points
3,086 views
+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
3,323 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,231 views
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,740 points
724 views
+1 vote
1 answer
0 votes
1 answer

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

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

answered Jul 12, 2018 in Blockchain by slayer
• 29,350 points
844 views
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,350 points
1,409 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP