sub IEEE80toIEEE64 { my $ieee80 = shift; # reverse the byte order; this makes it look like an Intel 80-bit doohickey my $ieee80r = join('', reverse(split //, unpack 'a10', $ieee80)); # now pick it apart my( $discard, $mantissa, $hidden, $exponent, $sign ) = unpack 'a11 a52 a1 a15 a1', unpack 'b80', $ieee80r; # readjust the exponent $exponent = unpack( 'v', pack 'b15', $exponent ) - 16383 + 1023; $exponent = 32767, $mantissa = '0' x 52 if $exponent < 0 or $exponent > 2047; $exponent = unpack 'b11', pack 'v', $exponent; # put it back together my $ieee64r = join('', $mantissa, $exponent, $sign); # reverse the byte order back to Motorola-normal my $ieee64 = join('', reverse(split //, unpack 'a8', pack 'b64', $ieee64r)); # ...and convert the binary to a Perl NV return unpack 'd', $ieee64; }