Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

CoiN

Union Troubles!

This topic is 6540 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Using the this union:
    
union test {
   double d;
   char c[8];
};
    
How would i display the double d () byte by byte using the char c[8]? Thanks in advance...

Share this post


Link to post
Share on other sites
Advertisement
I assume you want to display them as hex? try this:
        
printf ("0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
u.c[0], u.c[1], u.c[2], u.c[3], u.c[4], u.c[5], u.c[6], u.c[7]);


BTW, I tried to do this using cout <<...but I couldn't. I suck with streams.

Actually, I'm not sure how a double is packed in memory, so you may want to reverse the order of those bytes. Or they maybe be swapped around some other way. Something you could play with, I'm sure.

Edited by - Stoffel on July 25, 2000 1:11:48 PM

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!