编写了一个子函数,用于实现将十进制转换为十六进制
#include<iostream>
#include<cstdlib>
#include<vector>
using namespace std;
char *decimalToHEX(int input);/函数声明
int main()
{
char *p;
p=decimalToHEX(500);
for (size_t i = 0; i < sizeof(p)/sizeof(char); i++)
{
cout << *p;
p++;
}
system("pause");
}
char *decimalToHEX(int input)
{
int x;
vector<char> vec;
while (input>0)
{
x = input % 16;
input = input / 16;
if (x<10)
vec.push_back(x+48);
else vec.push_back(55 + x);
}
char *hex = new char[vec.size() - 1];
for (int i =0; i < vec.size() ; i++)
{
hex[i] = vec[vec.size()-i-1];
}
return hex;
}