如何在Linux中使用C ++将hex
格式的IP(例如0101007F)转换为Dotted Decimal
?
答案 0 :(得分:1)
您可以尝试这样:
static char* hexdecimal_to_decimalip(const char *in)
{
char *out = (char*)malloc(sizeof(char) * 16);
unsigned int p, q, r, s;
if (sscanf(in, "%2x%2x%2x%2x", &p, &q, &r, &s) != 4)
return out;
sprintf(out, "%u.%u.%u.%u", p, q, r, s);
return out;
}