#include<iostream>
#include<stack>
#include<string>
using namespace std;
stack<char> str;
void fun(long n)
{
while(n>0)
{
if(n%16>=10)
{
if(n%16==15)
str.push('f');
else if(n%16==14)
{
str.push('e');
}
else if(n%16==13)
{
str.push('d');
}
else if(n%16==12)
{
str.push('c');
}
else if(n%16==11)
{
str.push('b');
}
else if(n%16==10)
{
str.push('a');
}
}
else
{
str.push(n%16+'0');
}
n/=16;
}
if(n==0)
cout<<0;
if(n<0)
cout<<"data error";
while(!str.empty())
{
cout<<str.top();
str.pop();
}
}
int main()
{
long n;
cin>>n;
fun(n);
cout<<endl;
system("pause");
return 0;
}
十进制转换为十六进制
最新推荐文章于 2023-03-15 16:40:23 发布