发布网友 发布时间:2022-04-23 08:40
共2个回答
热心网友 时间:2022-04-27 16:31
#include <iostream>
using namespace std;
int main()
{
long int a;
int i;
cout<<"请输入一个整数:\n";
cin>>a;
cout<<"the ip is ";
for(i=0;i<3;i++)
cout<<( (a>>(24-i*8))&0x000000ff )<<".";
cout<<(a&0x000000ff)<<endl;
return 0;
}
热心网友 时间:2022-04-27 17:49
应该没有错 网吧里没编译器 错了hi我
#include <iostream>
#include <stdio.h>
using namespace std;
struct ipadress{unsigned byte ip1,ip2,ip3,ip4;};
(ipadress*) IntToip(unsigned int ipa){
ipadress *ip=new ipadress();
ip->ip1=0;
ip->ip2=0;
ip->ip3=0;
ip->ip4=0;
ip->ip4|=ipa;
ipa>>1;
ip->ip3|=ipa;
ipa>>1;
ip->ip2|=ipa;
ipa>>1;
ip->ip1|=ipa;
return ip;
}
void main(){
int i=0;
cin>>i;
ipadress* ip=IntToip(i);
printf("%x.%x.%x.%x",ip->ip1,ip->ip2,ip->ip3,ip->ip4);
}