Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: 32bit float from two halves

by hexcoder (Curate)
on Aug 10, 2016 at 21:16 UTC ( [id://1169528]=note: print w/replies, xml ) Need Help??


in reply to 32bit float from two halves

... my $var3 = unpack 'f', pack 'V', $var1 << 16 | $var2;
and you get your float in $var3.

Replies are listed 'Best First'.
Re^2: 32bit float from two halves
by thatmguy (Initiate) on Aug 10, 2016 at 22:42 UTC
    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...

      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...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1169528]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (11)
As of 2024-03-28 09:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found