题解 | #整数与IP地址间的转换#
整数与IP地址间的转换
https://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea
ip = list(map(int,input().split('.'))) # 10.0.3.193 n = int(input()) # 167969729 ans = '' # ip -> int for i in ip: ans += (bin(i)[2:].zfill(8)) print(int(ans,2)) # int -> ip bb = bin(n)[2:].zfill(32) ls = [] for i in range(0,len(bb),8): # 注意这里遍历的是位置,并且步长为8 ls.append(int(bb[i:i+8],2)) print('.'.join(list(map(str,ls))))