Hello,
how can I achieve
long l = WHAT_EVER_MACRO (-12.5); main() { printf("%X",l); }
resulting in output "0xC1480000" the binary representation of the float -12.5 . Without that MACRO the value is 0xFFFFFFF4 = -12 for integers .
Because of given circumstances in an existing project I have to store float values during initialization in long variables.
Is there any possibility?
Thanks in advance
Jürgen
Now I got you!
I tryed
float f32ConstInitval = -12.5; uint32_t ui32Testvalue = (*(uint32_t *)&f32ConstInitval);
and got: 'scalar': initializer is not a constant :-(
With
static const float f32ConstInitval = -12.5; uint32_t ui32Testvalue = f32ConstInitval);
I got ui32Testvalue = 0xFFFFFFF4 as I asked my debugger :-(
but with
static const float f32ConstInitval = -12.5; uint32_t ui32Testvalue = (*(uint32_t *)&f32ConstInitval);
I yielded my desired ui32Testvalue = 0xC1480000 :-D with a litte overhead of 4 Bytes in far flash.
Thanks a lot
or to make a pointer (void or unsigned long) and points it to the floater.