I'm writing a C++ program in which I need to display the bits that represent both a 32-bit and 64-bit floating point number. I had no problem properly displaying the 32-bit number, but I'm having trouble with the 64-bit number.
This is the code that I'm trying to use:
unsigned int* low = (unsigned int*)&doubleValue;
unsigned int* high = (unsigned int*)((&doubleValue)+4);
unsigned int mask = 0x80000000; // 1000 0000 0000 0000
unsigned int result;
for(int i = 31; i>=0; i--)
{
result = (*high & mask) >> i;
mask = mask >> 1;
cout << result;
}
mask = 0x80000000;
for(int i = 31; i>=0; i--)
{
result = (*low & mask) >> i;
mask = mask >> 1;
cout << result;
}
The variable 'doubleValue' is of type double and holds the number that I am trying to display in binary. I can get the lowest 32 bits to display correctly, its the highest 32 bits that I'm having trouble with.
Any help is greatly appreciated!