题解 | #整数与IP地址间的转换#
整数与IP地址间的转换
https://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea
while True: try: #IP地址转整数: s = input().split('.') s = [bin(int(i))[2:].rjust(8,'0') for i in s] l = '' for i in s: l += i print(int(l,2)) #整数转IP地址: n = int(input()) k = bin(n)[2:].rjust(32,'0') print(k) m = [] for i in range(0,len(k),8): m.append(int(k[i:i+8],2)) print('{0}.{1}.{2}.{3}'.format(m[0],m[1],m[2],m[3])) except: break