#include <stdio.h>
#include <math.h>
int main()
{
int num[4] = {0};
int i = 0;
int z = 0;
int k = 7;
char arr[40] = { '\0' };
gets(arr);
for( i = 0 ; i < 32 ; i++)
{
if( (i+1) % 8 != 0 || i == 0 )
{
num[z] = num[z] + (arr[i]-'0')*pow(2,k);
k--;
}
else if( (i+1)%8 ==0 )
{
num[z] = num[z] + (arr[i]-'0')*pow(2,k);
k--;
k = 7;
z++;
}
}
for( i = 0 ;i < 4 ; i++)
{
if( i == 0 )
printf("%d",num[i]);
else
{
printf(",%d",num[i]);
}
}
return 0;
}
IP地址转换
![](https://img-home.csdnimg.cn/images/20240711042549.png)