in reply to Unpacking Floating Point on architectures with different endians

This won't be easy. As you can verify by looking at the documentation for pack, the "v" format is portable, but floats and doubles are only supported in native machine format. The problem that causes this goes back to how C handles floats. If at all possible, you really want to convert the float to something portable, and transmit that instead.

If you don't want to go that way, then you're going to have to not use unpack. Instead you'll have to do some custom bit-twiddling to parse the float format and make it come out right.

  • Comment on Re: Unpacking Floating Point on architectures with different endians

Replies are listed 'Best First'.
Re: Re: Unpacking Floating Point on architectures with different endians
by davido (Cardinal) on May 04, 2004 at 07:00 UTC
    tilly's response reminded me of a key tidbit that I read in perlpacktut:

    Floating point Numbers

    For packing floating point numbers you have the choice between the pack codes f and d which pack into (or unpack from) single-precision or double-precision representation as it is provided by your system. (There is no such thing as a network representation for reals, so if you want to send your real numbers across computer boundaries, you'd better stick to ASCII representation, unless you're absolutely sure what's on the other end of the line.)


    Dave