0

Am trying to convert this hex value to int and I get invalid litrel error in python 3.7

>>> int('1.222664064E9', 16)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 16: '1.222664064E9'
AMC
  • 2,642
  • 7
  • 13
  • 35
SUN
  • 87
  • 1
  • 12
  • The `E` does not mean that it's a hex value but 1.22...*10^9 – tobias_k Jul 10 '20 at 18:14
  • I was wrong, it was a float value, Thanks for pointing it out – SUN Jul 10 '20 at 18:20
  • What do you understand from that error message? – AMC Jul 10 '20 at 18:21
  • 3
    Does this answer your question? [ValueError: invalid literal for int() with base 10: ''](https://stackoverflow.com/questions/1841565/valueerror-invalid-literal-for-int-with-base-10) – AMC Jul 10 '20 at 18:22

1 Answers1

2

Use float.fromhex:

>>> float.fromhex('1.222664064E9')
1.1333982959172886
>>> int(_)
1

Although are you sure it's hex? It looks like a float in exponent notation, where E9 stands for * 10 ** 9:

>>> float('1.222664064E9')
1222664064.0
>>> int(_)
1222664064
wjandrea
  • 28,235
  • 9
  • 60
  • 81