Paul G. Allen wrote:
> On Wed, 2007-03-07 at 14:23 -0800, Andrew Lentvorski wrote:
>
> >
> > That's not 31.31 even if I *do* extend that to the correct number of bits.
> >
>
> I seem to have lost a few bits in my copy-n-paste:
>
> 10001111 11000010 11110101 101000 1011100 1001111 111111 1000000
8 f c 2 f 5 2 8 5 c 8 f 3 f 4 0
> > See: http://babbage.cs.qc.edu/IEEE-754/Decimal.html
> >
> > 31.31 == 403F4F5C28F5C28F
Normalise the input for endian and MSB and all should be easier.
$number =~ /^([01])([01]{11})([01]{26})([01]{26})$/;
$s=$1; $e=eval "0b$2"; $f1=eval "0b$3"; $f2=eval "0b$4";
$f=$f1 * 1<<26 + $f2;
$f=eval "1.$f";
$double=-1***$s * 2 **($e-1023) * $f;
Not perfectly tested, as I did not normalise the input for endian and
MSB order, nor for the strange corner cases that the spec shows.
It's a start, though.
Good luck!
-john
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg