Click to See Complete Forum and Search --> : ByteString to Double value! Something wrong!!!!!!!!


shivakumarthota
July 1st, 2002, 01:49 AM
I have a problem:
I wanted to convert a byteString to Double. The ByteString is sent by a remote server and I have to convert this to a double. After receving few ideas from this very forum I was able to fix this problem.

But a new problem has surfaced. When a byteString that is sent has less than eight bytes, I am not able to convert it to the correct double value.

For example, If I received a value 4E40, which is of two bytes and whose decimal value is 60. My program gives me an output that looks like ::: 60000000

that is the rest of the eight bytes of a double value are being padded with zero's.

Please suggest and help me. Thank you in advance

Shivakumar Thota
shivatk@hotmail.com

cup
July 1st, 2002, 03:53 AM
Have a look at

http://www.codeguru.com/forum/showthread.php?s=&threadid=195805

If you are getting 4E40, why not just make it 4E400000 or 00004E40 (I don't know which way the padding is done) and overlay it with a double as specified in the URL.

stober
July 1st, 2002, 10:54 PM
If you try this little experiment:

unsigned char buf[16]; // must be at least 8 bytes
memset(buf,0,sizeof(buf));
double x = 60.0F;
memcpy(buf,&x,sizeof(double));

Then look at each of the bytes in buf, they are: 0 0 0 0 0 0 4E 40

double x = *(double *)buf will convert the buffer to double. If the buffer is not 8 bytes, then pad it on the left to make it big enough.

shivakumarthota
July 6th, 2002, 12:00 AM
Thanks for all your help friends. It was a silly problem during integration and the twiddledouble() what I had written worked excellently. Sorry for troubling you and Once again thank you very much