-1

how to convert a hex number to float i use this in C

HexTofloat float (uint32_t x){
   return (* (float *) & x);
}
i = HexTofloat (1130839281);
print (i); //result 231.24

How does it work? i want to make it in python

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190

3 Answers3

0

You must use float.fromhex and float.hex

float.fromhex('0x1.5c28f5c28f5c3p-1')
Output: 0.68
0

you can use in-built function of python like this : float.hex(num)

Gunaraj Khatri
  • 153
  • 3
  • 13
0

You can use a library which is known as ast
To install this library you need to type:- pip install AST
eg:-

from ast import literal_eval 
data = "0xAB15"
out = literal_eval(data) 
print(out)

you will get the output:- 43797