10进制转36进制,输出为4位定长
// 10进制转36进制,输出4位定长
#include <windows.h>
#include <iostream>
#include <math.h>
using namespace std;
char Tranf16(int a);
int main()
{
int test=10000;
int s3=pow(36,3);
int s2=pow(36,2);
int max_10=s3*35+35*s2+35*36+35;
int value_10;
int chushu[4];
int yushu[4];
cout<<"请输入10进制正整数"<<endl;
cin>>value_10;
if (value_10>max_10)
{
cout<<"输入的10进制超过范围"<<endl;
return 0;
}
int temp_10=value_10;
chushu[0]=value_10/36;
yushu[0]=value_10%36;
int i=0;
while (temp_10/36)
{
yushu[i]=temp_10%36;
temp_10=temp_10/36;
i=i+1;
}
yushu[i]=temp_10%36;
char *value_36=new char[5];
value_36[4]='\0';
int k;
for (k=0;k<3-i;k++)
{
value_36[k]='0';
}
for (int j=i;j>=0;j--)
{
value_36[k]=Tranf16(yushu[j]);
k++;
}
cout<<value_36<<endl;
if (value_36!=NULL)
{
delete value_36;
}
}
char Tranf16(int a)
{
char table16[37]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
return table16[a];
}