题解 | #整数与IP地址间的转换#
整数与IP地址间的转换
http://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea
def iptoint(s):
ip_list=s.strip().split('.')
n=''
for i in ip_list:
n+=bin(int(i))[2:].zfill(8)
result=int(n,2)
return result
def inttoip(s):
ip=''
n=bin(int(s))[2:].zfill(32)
for i in range(0,32,8):
ip+=str(int(n[i:i+8],2))
ip+="."
return ip[:-1]
while 1:
try:
ip=input()
num=input()
print(iptoint(ip))
print(inttoip(num))
except:
break