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
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
You must use float.fromhex
and float.hex
float.fromhex('0x1.5c28f5c28f5c3p-1')
Output: 0.68
you can use in-built function of python like this : float.hex(num)
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