2023-02-20 08:09 AM
Hello,
I am having a problem with simple line of code. If I run code bellow, the result seems off.
//Main job of this code is to tranform hex into float
uint32_t hex = 0x3fc51eb8;
float f;
memcpy(&f, &hex, 4);
If i go into Live Expressions i get that f = 0x1 (hex), it should be f = 0x3fc51eb8. The strangest thing is that the same code works for example on an onlineGDB compiler.
I assumed the trouble was within compiler, therefore I tried to change from default GNU 11 to some others, but there were no change. Any idea what could be wrong?
I am using:
NUCLEO G474
cubeIDE Version: 1.10.1 Build: 12716_20220707_0928 (UTC)
2023-02-20 08:39 AM
I found out that everything works fine except maybe cubeIDE (Number format option in debug perspective). The problem is that there is something wrong with hex Number format. If the number format is set as Default, then floats have correct values. Is there a bug inside cubeIDE or do I not understand what does Number format option do.
I added another variable (float test = 5.3) inside the code from previous post. By changing Number format option i get.
Is this kind of behavior anticipated?
2023-02-20 08:43 AM
Seems unhelpful, but 1.54 probably doesn't print well as the actual number, in hex.