begin  quoting Paul G. Allen as of Wed, Mar 07, 2007 at 10:31:02AM -0800:
> On Wed, 2007-03-07 at 10:10 -0800, Stewart Stremler wrote:
> > begin  quoting Paul G. Allen as of Wed, Mar 07, 2007 at 09:18:52AM -0800:
> > > It's been a while (years?) since I've done anything in Perl. I need to
> > > convert an ASCII string of ones and zeros to a double. (Actually, I
> > > don't need to, but one of our engineers does.)
> > 
> > As in a floating point?
> 
> The exact request the I got was:
> 
> "I spent more than 4 hours to convert the following binary string to
> double number using pack and unpack.
> 0100000000000110010111111100101100100101111111001011001001100000"
> 
> He said he was unsuccessful.

Hm...

0100000000000110010111111100101100100101111111001011001001100000
          1         2         3         4         5         6  |      7
01234567890123456789012345678901234567890123456789012345678901234567890

It could be an IEEE 754 double.

Bit 0 = sign bit (S)
Bits 1 - 11 = exponent (E)
Bits 12-63 = fraction (F)

So the formula is (if I transcribe this correctly)

V = (-1)^S * 2^(E-1023) * 1.F

Since the E is 1024, and S is 0, we get

V = 2 * 1.F

Where 1.F is the F part with "1." prefixed on the front.

-- 
I get 1.3983870967741935942285635974258144329833984375 from bc for 1.F.
Stewart Stremler

-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to