数据转化为IP(转载注明出处!!!)

#include <stdio.h>
#include <string.h>
char in[30]={0};
char out[70]={0};
int temp;
void f(char* input,char*output)
{
int len;
int i,j,m=0,t;
_int64 a=0,b=0;
len = strlen(input);


for(i = 0; i <len;i++)
{
a = a*10+(input[i]-48);

}
for(i=0,m=0;a;i++,m++ )
{
output[i] =a%2;
a =a/2;
}
temp=m-1;
for(i=m-1;i>=0;i--)
{
printf("%d",output[i]);
}


printf("\n");
}
int main()
{
int a=0,b=0,c=0,d=0;
int i;
while(scanf("%s",&in)!=EOF)
{

f(in,out);
a=0;
if(temp>=8)
{
for(i =temp;i>temp-8;i--)
{
a=a*2+(int)(out[i]);
}
}
else
{
for(i =temp;i>=0;i--)
{
a=a*2+(int)(out[i]);
}
}
// printf("%d.",a);
b=0;
if(temp>=16)
{
for(i =temp-8;i>temp-16;i--)
{
b=b*2+(int)(out[i]);
}
}
else if(temp>=8)
{
for(i =temp-8;i>temp%8;i--)
{
b=b*2+(int)(out[i]);
}
}


// printf("%d.",b);
c=0;
if(temp>=24)
{
for(i =temp-16;i>temp-24;i--)
{
c=c*2+(int)(out[i]);
}
}
else if(temp>=16)
{
for(i =temp-16;i>temp%16;i--)
{
c=c*2+(int)(out[i]);
}
}
// printf("%d.",c);
d=0;
if(temp>=32)
{
for(i =temp-24;i>temp-32;i--)
{
d=d*2+(int)(out[i]);
}
}
else if(temp>=24)
{
for(i =temp-24;i>temp%24;i--)
{
d=d*2+(int)(out[i]);
}
}
printf("%d.%d.%d.%d\n",d,c,b,a);


}
return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值