Double to Byte Array and Back
Author Message
Double to Byte Array and Back

Anyone understand how a double is written to file in binary mode??

I've examined it till blue in the face and can't figure where to place the
decimal when decoding when retrieving data as a byte array.

My goal is convert a bunch of data to byte array for sending via winsock.

I know it can be done by coercion with variants but I'd like to do the math
myself.

Thanks,

dj

Tue, 04 Jan 2000 03:00:00 GMT
Double to Byte Array and Back

IEEE doubles are complicated.  They're stored in 8 bytes, laid out like
this (the order of bytes is reversed here for clarity):

SEEEEEE EEEEMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM .....

...where S is the sign bit, EEE are exponent bits, and MMM are mantissa
bits.

The exponent is biased +1023, and the MSB of the mantissa is implied.

Decoding these is not trivial, and even less so in a language like VB
that has minimal support for masking and shifting.

-- Jim

Quote:

> Anyone understand how a double is written to file in binary mode??

> I've examined it till blue in the face and can't figure where to
place the
> decimal when decoding when retrieving data as a byte array.

> My goal is convert a bunch of data to byte array for sending via

winsock.

Thu, 06 Jan 2000 03:00:00 GMT
Double to Byte Array and Back

Thanks for the reply Jim.  At least now I understand why I see the
workarounds for this issue. (And why the decimal point kept moving
around on me).   I spent the last two weeks with my 8th grade Geometry
book (circa 1971), lord knows which one I'll have to dig out for this
<g>.

Quote:
>IEEE doubles are complicated.  They're stored in 8 bytes, laid out like
>this (the order of bytes is reversed here for clarity):

> SEEEEEE EEEEMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM .....

>...where S is the sign bit, EEE are exponent bits, and MMM are mantissa
>bits.

I'm thinking not so bad then I read the next line....I'm easily
confused <g>
Quote:
>The exponent is biased +1023, and the MSB of the mantissa is implied.

Most assuredly, (been cheating here with VBHelp32.dll or VBUtil.DLL)

Quote:
>Decoding these is not trivial, and even less so in a language like VB
>that has minimal support for masking and shifting.

>            -- Jim

I certainly hate using VB's "Type Coercion" or the  "out to file and
back" workaround though.