题解 | #整数与IP地址间的转换#
整数与IP地址间的转换
https://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea
import re a=input() b=input() i1=a.split(".") x=[] for i in i1: i=bin(int(i)) i=str(i)[2:] x.append(i.zfill(8)) string="".join(x) ipv4=int(string,2) print(ipv4) b=int(b.strip()) string1=bin(b)[2:].zfill(32) string2=re.findall(r'.{8}', string1) string3='' for i in string2: i=int(i,2) string3=string3+"."+str(i) string3=string3[1:] print(string3)