用C把整数转换成Ip地址

#define PRINT_IP_FORMAT         "%u.%u.%u.%u"
#define  PRINT_HIP(x)\
   ((x >> 24) & 0xFF),\
   ((x >> 16) & 0xFF),\
   ((x >>  8) & 0xFF),\
   ((x >>  0) & 0xFF)

char ip_str[64];
sprintf(ip_str, PRINT_IP_FORMAT, PRINT_HIP(ip));
printf("num  %u is ip %s \n", ip, ip_str);

你可能感兴趣的:(c,IP,十进制,整数)