If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

convert 8 bytes into double and back?

I have a question. I receive a byte stream. The first 8 bytes contain an Identification number. I receive at first the lowest byte and at the end the highest byte of the number.
How can I transform this into a double value and later back into the bytestream? In the past I hard only 2 Byte values and there I could use things like MAKEWORD and HIBYTE and LOWBYTE to convert the values

Re: convert 8 bytes into double and back?

if the 8 bytes represent an actualdouble in the double format...

1) use a Union of a double and an array of 8 bytes.
2) store the bytes in an 8 byte array, the copy the contents into a double with memcpy()
3) store in an array, then typecast the array pointer to a double pointer and dereference.
...

now. if the 8 bytes aren't in double format. you'll need to convert, can't help you there without more info.

Re: convert 8 bytes into double and back?

Basically there are 52 bits for the fraction part, 11 bits for the exponent and 1 bit for the sign. From the OP post #1, the 8 bytes represent an identification number which is probably an integer and not a floating point (double) number so a double number cannot be used correctly to store the id.

The type you probably need is long long or __int64 (both 8 byte integer).

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.