1. 十进制----十六进制
std::string decstr2hexstr(std::string str)
{
uint32_t num = std::stoul(str);
std::string ret;
for(int i = 3; i >= 0; --i)
{
ret.push_back("0123456789ABCDEF"[(((uint8_t*)&num)[i] >> 4) & 0xF]);
ret.push_back("0123456789ABCDEF"[((uint8_t*)&num)[i] & 0xF]);
}
return ret;
}
2. 十六进制----十进制
std::string hexstr2decstr(std::string str)
{
uint32_t num = std::stoul(str, 0, 16);
return std::to_string(num);
}