CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2002
    Location
    Hyderabad, India
    Posts
    24

    Question 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

  2. #2
    Join Date
    Jun 2002
    Location
    Letchworth, UK
    Posts
    1,020
    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

  3. #3
    Join Date
    Jun 2002
    Posts
    1,417
    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.

  4. #4
    Join Date
    May 2002
    Location
    Hyderabad, India
    Posts
    24

    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
  •  





Click Here to Expand Forum to Full Width

Featured