|
-
July 1st, 2002, 01:49 AM
#1
ByteString to Double value! Something wrong!!!!!!!!
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
[email protected]
Shivakumar Thota
-
July 1st, 2002, 03:53 AM
#2
Have a look at
http://www.codeguru.com/forum/showth...hreadid=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.
Succinct is verbose for terse
-
July 1st, 2002, 10:54 PM
#3
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.
-
July 6th, 2002, 12:00 AM
#4
Thanks!
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
Shivakumar Thota
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|