in reply to Re: 32bit float from two halves
in thread 32bit float from two halves

Makes sense - reverse and pack two shorts, then unpack as float vs build a long, reverse/pack it as a long, then unpack as float. Thanks for both solutions, it's pretty cool to see the proverbial cat skinned multiple ways...

Replies are listed 'Best First'.
Re^3: 32bit float from two halves
by Anonymous Monk on Aug 10, 2016 at 23:02 UTC

    Just to make sure the right idea gets across — the reverse as seen here merely changes argument order and is otherwise irrelevant. (It's quicker to type in "reverse" than to swap those numbers in a command line.)

      Aha, ok. Is there then an endianness change implied in the arguments to pack? The two parts of the value are coming from some sort of industrial control unit; we don't have any info on what the internal architecture of the unit is so we're trying to document exactly what needed to be done to the data to get it readable via perl on linux/Intel. Thanks again for the insight, this is really helping...
        Exactly, see perlpacktut#Byte-order-modifiers

        unpack() can unpack little and/or big endian in one go. In that page, read also the part titled "Dealing with Endian-ness".