题解 | #整数与IP地址间的转换#
整数与IP地址间的转换
https://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea
s = list(map(int, input().split('.'))) num = [] for item in s: num.append('{0:0>8s}'.format(bin(item)[2:]))#bin运算后返回类型为字符串类型 print(int(''.join(num), 2)) s1 = int(input()) a = '{0:0>32s}'.format(bin(s1)[2:]) num2 = [] for i in range(0,len(a),8): num2.append(str(int(a[i:i+8], 2)))#数字列表无法使用join,只有以字符串为元素的列表才可以 print('.'.join(num2))