hhave downloaded this program that convert binary numbers to decimal number. But, I found that it works properly with binary numbers upto 10 digits. It gives wrong results with 11 and more binary digits.
would any one help me to develope the program or at least tell me how to fix this problem.
the program as shown below:
//--------------------this program allow user to convert binary to decimal and Decimal to binary --------------
//-------------------- tested unber C++ Builder 6 (Borland)-----------------------
//-------------------- created by holy_spirit ------------------------------------
See, the problem is that whoever wrote this was a total noob at the time.
He made several mistakes, like getting user input from a conversion function, using ints to store binary digits that will be converted to decimal, and using pow().
A 32-bit signed int can hold any integer in the range [-2^31;2^31-1]. 2^31 happens to have 10 decimal digits.
Now, the problem is that, since this is a binary number that will be converted to decimal, the minimum number of bits the user should be able to input is the size of a long (in this case, 32 bits). There is no integer large enough to hold that, so the bits should be stored as a string.
That program is made of fail. I could a better one with my eyes closed.
As a matter of fact,