Answer the question
In order to leave comments, you need to log in
How to do hex to float conversion correctly?
Good day. I am studying programming MK STM32F103, a problem arose. Why does this conversion error occur?
float Variable;
Variable = 0x3EAE147B; // in decimal - 0.340
Immediately after this operation, the debugger writes that Variable is equal to 0x4E7AB852, so the number is completely different (1.015).
Thanks for the help!
Answer the question
In order to leave comments, you need to log in
We've given float an integer. Union must be used.
union {
float asF;
uint32_t asI;
};
asF = 0x3EAE147B; // в десятичной - 0.340
std::cout << asF << ' ' << std::hex << asI << std::endl;
asI = 0x3EAE147B;
std::cout << asF << ' ' << std::hex << asI << std::endl;
return 0;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question