Hello all,
I want to take a floating point number and determine it's binary
represention.  This seems easy enough as the answer is right there in
memory.  I can do this with a debugger, but other than dicking around with
memcopies, I can't see an easy way to print out the memory contents of
arbitrary data.

So here is what I have thus far (I know, it's a disgusting conglomeration of
C and C++ but that's how I code).
----------------------------------------------------------------------------
---------------------------------------------------------------------------

#include <iostream.h>
#include <string.h>
#include <iomanip.h>

main()
{
        float f = 903996940.376776;
        double d = 903996940.376776;


        unsigned int i_f,i_d1,i_d2;
        memcpy ( (void*)&i_f, (void*)&f,4);
        memcpy (  (void*)&i_d1, (void*)&d,4);
        memcpy (  (void*)&i_d2, (void*)((&d)+4),4);
        
        cout <<hex<<&d<<"\t"<<(&d)+4<<"\t"<<i_f<<"\t"<<i_d1<<"\t"<<i_d2<<
endl;
}

Here is the output
-----------------------------------------------------

1       1       4e578798        6303a32 0

----------------------------------------------------------------------------
------------------------------------------------------------

What seems wrong is that &d and (&d)+4 have the same value (and it's
apparently 1 ??).  Because doubles are 64-bit, I tried to partition the
memcopy into two separate ints.  However, I've done something silly whilst
trying to increment 4 bytes in memory.  It seems like simple pointer
arithmetic to moi, so I'll ask some good coders -- what gives?

Thanks,
Andy

Reply via email to