CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2001
    Posts
    52

    Question How to access a byte within a double

    How can I access Bytes (8) in a double Variable. I need to access all 8 Bytes of a double. I need to convert each Byte of the double to an Hex-Value (String).

  2. #2
    Join Date
    Jun 2002
    Posts
    1,417
    double value = 123.456F;
    char* ptr = (char *)&value;

  3. #3
    Join Date
    Oct 2001
    Posts
    52

    Lightbulb Hmmmh....

    But how can I access for example the 3rd Byte?

  4. #4
    Join Date
    Jun 2002
    Posts
    1,417
    double value = 123.456F;

    unsigned char* ptr = (unsigned char *)&value;

    // now you can treat the double as if it were any other array of char bytes

    unsigned char third_byte = ptr[2];

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