Hello ,

I have a transferred a file from an IBM mainframe to a windows platform that
I need to analyse. The file contains an 8 byte floating point hexadecimal
representaion 44FE880000000000.

This should be converted to the number 65160.

I created the following subroutine which works ok but it does alot
of work. Is there something more efficient ?

 # first byte (value-40) - get exponent base 16;
 # next 7 bytes (sum for each bit) - (1/2)** exponential for each bit
 # result = sum of all bits * (16 ** exponent)

sub floatmvs {
 my $mat=0;
 my $firstbyte = unpack "H2", $_[0];
 my $exp=$firstbyte-40;  # base 16
 my $bin=unpack('B*',substr($_[0],1,7));
   for ($start=0; $start <56; $start+=1) {
        $bit=substr($bin,$start,1);
        $bitpos=$start+1;
        if ($bit == 1) {
            $val=(1/2)**($bitpos);
            $mat=$mat+$val;
        }
   }
   my $num=$mat*(16**$exp);
   return $num;
}





                        Thanks Mark


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to