Click here to Skip to main content
16,014,633 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Can I write a project in C++ that converts numbers from decimal to binary?
Or a program that calculates sum of binary numbers, does multiplication and division?
If I can how do that what is the basic idea for the programs?
Posted
Updated 14-May-10 13:08pm
v2

Yes, you can do any of these things, assuming you understand how numbers are represented in computers. Try using functions such as atoi (take a look at the MSDN documentation) to convert your strings to numbers, and printf() to display your results. You can also use cin and cout but it is less likely to enhance your levels of understanding.
 
Share this answer
 
Simple example to convert from decimal to binary:

long Convert(int x) {
	
	int i;
	int mod;
	long double_ = 0;

	for (i = 0; x>0; i++) 
        {
	
		mod =  x % 2;
		x = (x - mod) / 2;
		double_ += mod * pow((double)10,i);
	}
	return double_;

}
 
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