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.  

Thanks for your time,

dj



Mon, 17 Jan 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Copying a long array into a byte array and back

2. Copying a long array into a byte array and back

3. Copying a long array into a byte array and back

4. Copying a long array into a byte array and back

5. Copying a long array into a byte array and back

6. byte array to double

7. Convert byte array to double? VB5.0

8. converting floating point dtaa from byte array to DOUBLE

9. Convert Byte Array To Double

10. Convert Byte Array to Double.

11. Convert Byte Array to Double using CopyMemory

12. Convert Strings to Byte arrays and back

 

 
Powered by phpBB® Forum Software