Archived

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

CoiN

Union Troubles!

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
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