#include <stack>
#include <iostream>
using namespace std;
//N原数字 d进制
void conversion(int N,int d)
{
stack<int> s;
int x;
while(N) {
s.push(N%d);
N=N/d;
}
while (!s.empty())
{
switch (s.top())
{
case 10:
cout<<"A";
break;
case 11:
cout<<"B";
break;
case 12:
cout<<"C";
break;
case 13:
cout<<"D";
break;
case 14:
cout<<"E";
break;
case 15:
cout<<"F";
break;
default:
cout<<s.top();
}
s.pop();
}
}
//测试
int _tmain(int argc, _TCHAR* argv[])
{
conversion(30,16);
system("pause");
return 0;
}
输出 : 1E