Change number from(base 2,base 3...To base 9) to give number in base 10=(decimal)
if u enter number 1352 base 8 give u number 746 in decimal.
My program is based one 2 line:
1-decimal=Quotient*b+array[j]; u may change this for decimal=array[j];
>> i used j to take first number in array that will be 1 in ex. <<
I have another problem when i enter number like 1352 to change it to decimal i have to enter 1 and make Enter than enter 3 and make Enter than..........
i try To change int array with char array and it work but give number wrong more than int.
So I hope one find solution to but number 1352 with out Partition.
I hope all answer me soon :)
This Is the Code:
using namespace std;
cout<<"Enter Base Number :";
cout<<"\n Enter Bits of number : ";
cout<<"\n Enter number : ";
cout<<"\nDecimal Number is :"<<decimal;
and i had done New Program Can Change from any base To any base but i have
didn't add from base (11:16) .
i don't know how make program read number like this 2EA in 16 To change it .
i hope u try my code and see if u can add it and write here code.
using namespace std;
cout<<"Enter Base your Number u will Enter :";
cout<<"\nEnter number : ";
cout<<"\nEnter The Base u will Change To it : ";
cout<<"\nDecimal Number is :"<<DecimalNumber<<endl;
temp=DecimalNumber % B;
why u add const std::string digits = "0123456789ABCDEF";
That's just to make things easier to look up. digits = '0', digits = '1', ..., digits = 'E', digits = 'F'.
num.length() What it mean to add length() ?
num.length() is the length of the string num. It makes sure that the loop will go over every digit in the number.
value += (int)digits.find(num[i]) * pow(from, (int)num.length() - i - 1);
The find function will look through the digits string ("0123456789ABCDEF") for the position of the current digit in num. EG looking for '5' gives 5, looking for 'C' gives 12, etc.
Then the value of the position is multiplied by a power of the base you're converting from. If the number has 3 digits, then the first digit (on the left) is multiplied by from * from * from. The second by from * from, and the third by from. The results are added to value. Basically, the loop converts the number to base 10.
while (value > 0)
int digit = value % to;
value /= to;
newnum.insert(0, 1, digits[digit]);
This loop converts a base 10 number to whatever base "to" is. You can find the reasoning in fun2code's post.
I find when i enter small letters don't give correct answer ??
As I said, it doesn't check for input errors. The digit string "0123456789ABCDEF" does not contain any lower case letters.