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

Re: Converting binary to double precision (big-endian)

by BrowserUk (Patriarch)
on Feb 24, 2014 at 19:06 UTC ( [id://1076025]=note: print w/replies, xml ) Need Help??


in reply to Converting binary to double precision

Your value comes from a big-endian system, so you'll need 'd>' to decode it:

$n = pack 'H16', '3f0df9673344c570';; print unpack 'd>', $n;; 5.71713084433029e-005

You could also do the byte swapping yourself:

$n = pack 'H16', '3f0df9673344c570';; print unpack 'd', scalar reverse $n;; 5.71713084433029e-005

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Converting binary to double precision (big-endian)
by ahoriuch (Acolyte) on Feb 24, 2014 at 21:34 UTC

    In my case, this was the correct answer. I needed to switch from big to little-endian. It's amazing how little there is on the internet on this subject. Hopefully this will help future users.

    my $n = pack 'H16', '3f0df9673344c570';; printf "Big\n"; print unpack ("d", scalar reverse $n); #Big #5.71713084433029e-05 printf "\nLittle\n"; print unpack ("d",$n); printf "\n"; #Little #1.69044404965372e+235

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-19 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found