Home > Back-end >  System converter problem
System converter problem

Time:12-09

#include
#include
#include
using namespace std;
Int fun (int n, int k, vector A, int x);
Void f (int x, int m);
Void main ()
{
Int n, k, m, I;
Int x=0;
cout<" * * * * * * * * * * welcome to system converter * * * * * * * * * * "& lt; cout<" Please enter the number into the system, ";
cin> k;
cout<" Please input is converted to hexadecimal: ";
cin> m;
cout<" Please input the number of digits: ";
cin> n;
Vector A (n);
cout<" Please input the number: ";

for(i=0; i{
cin> A, [I].
}
cout<" With "& lt; X=fun (n, k, a, x);
F (x, m);
}
Int fun (int n, int k, vector A, int x)
{
int i;
for(i=0; i{
The switch (a [I])
{
Case '0' :
a[i]=0;
continue;
Case '1' :
A [I]=1;
continue;
Case '2' :
A [I]=2;
continue;
Case '3' :
A [I]=3;
continue;
Case '4' :
A [I]=4;
continue;
Case '5' :
A [I]=5;
continue;
Case '6' :
A [I]=6;
continue;
Case '7' :
A, [I]=7.
continue;
Case '8' :
A [I]=8;
continue;
Case '9' :
A [I]=9;
continue;
Case 'A' :
A [I]=10;
continue;
Case 'B' :
A [I]=11;
continue;
Case 'C' :
A [I]=12;
continue;
Case 'D' :
A [I]=13;
Case 'E' :
A [I]=14;
continue;
Case 'F' :
A [I]=15;
continue;
Default:
continue;
}
}
for(i=0; i{
X +=(int) (a) [I] * (pow (k (n - I - 1)));
}
return x;
}
Void f (int x, int m)
{
Int I=0, j, b [20].
for(; x!=0; I++)
{
B [I]=x % m;
X=x/m;
}
For (j=I - 1; J>=0; J -)
{
The switch (b [j])
{
Case 10:
cout<" A ";
continue;
Case 11:
cout<" B ";
continue;
Case 12:
cout<" C ";
continue;
Case 13:
cout<" D ";
continue;
Case 14:
cout<" E ";
continue;
Case 15:
cout<" F ";
continue;
Default:
B [j]=(char) (b) [j];
coutcontinue;
}
}
cout}



I this code can only be implemented once number system conversion, is there any one who teach me how to implement multiple number system conversion?

CodePudding user response:

Just reply to a decimal hexadecimal example can participate

CodePudding user response:

On the question, I want to know how to continue to convert the value, I only once, the code above,

CodePudding user response:

See example should understand to learn packaged into function can be called repeatedly,
  • Related