Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm looking for a function which convert the decimal fraction i have in real, to a binary var.

Can anyone please help me on this one...

Thnx
Posted

1 solution

Here is a function that I have written before. It prints a float variable in 1's and 0's as it is stored in the memory (it is stored with the IEEE single precision floating point numbers standard).

void printFloat(float a)
{
	unsigned long* temp = (unsigned long*)&a;
	unsigned long one = 1;

	for(int  i = 31; i >= 0; i--)
	{
		if(((*temp) & (one << i)) == 0)
			cout << "0";
		else cout << "1";

		if (i % 4 == 0)
			cout << " ";
	}

	cout << endl;
}


I'm not sure if this is what you need. Hope it helps.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900