Re: Decimal to floating point and floating point to decimal conversion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 10 Jul 2023 at 19:23, <henri.cloetens@xxxxxxxxxx> wrote:
>
> Hello Amit,
>
> If you want to do this conversion in C, proceed as follows :
>
> #include "stdio.h"
> #include "stdlib.h"
>
> int main()
> {
> float a = 3.2444422 ;
> int *p = (int *)(&a) ;
> fprintf(stderr,"%08x\n",*p) ;
> }
>
> It will print the hex value, which happens to be the same as yours on my
> machine.

That code has undefined behaviour.

This would be valid:

float a = 3.2444422 ;
int i;
memcpy(&i, &f, sizeof(int));
fprintf(stderr,"%08x\n",i) ;



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux