I'm kind of stumped on a project. The purpose of the project is to decode a floating point number to find it's sign, exponent, and significand, etc...
So far I've been able to get a user input float number into binary32 format using few lines of assembly code(professor told us to do it that way.)
Here is what I have so far:
#include <iostream>
using namespace std;
int main()
{
unsigned int mask = 0x80000000;
float fvar = 0;
unsigned int ivar;
// cout << "Hex value: " << hex << iValue << "\n\n";
cout << "Enter a floating number: ";
cin >> fvar;
cout << "\n\n";
_asm
{
MOV EAX,fvar
MOV ivar,EAX
}
for (int x = 0; x < 32; x++)
{
if(x % 8 == 0 && x != 0)
cout << "-";
if(ivar & mask)
cout << "1";
else
cout << "0";
ivar = ivar << 1;
}
cout << "\n\n";
return 0;
}
I am able to print the binary representation of any float number that is put in, but I'm stuck there.
How do I use bit shifting to find the "sign" of the number and display it on the screen?
or is there another way of finding the sign? Maybe by using a mask?