in reply to Converting Hex to Float (and vise versa)


Here is one way of doing it:
#!/usr/bin/perl -wl my $hex = '0x428C0000'; $hex =~ s/0x//i; # Strip the hex 0x if present print unpack "f", reverse pack "H*", $hex ; print unpack "f", pack "H*", $hex ; __END__ Prints on an a little endian platform: 70 5.03150226600469e-041

In this case the first of these looks like the right value.

It is rare that you will encounter a platform where one of these doesn't work. If you do then I have some Perl code for packing and unpacking IEEE 754 floats and doubles independently of the architecture.

--
John.