题解 | #整数与IP地址间的转换#
整数与IP地址间的转换
https://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea
ip1 = input() ip2 = input() out1= "" for p in ip1.split("."): out1 += bin(int(p))[2:].rjust(8,'0') out1 = int(out1,2) #截断0b out2 = bin(int(ip2))[2:].rjust(32,'0') #分四段 out3 = [] for i in range(4): t = out2[8*i:8*i+8] out3.append(str(int(t,2))) print(out1) print(".".join(out3))