题解 | #整数与IP地址间的转换#
整数与IP地址间的转换
https://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea
#s='00001010000000000000001111000001' #print(int(s,2)) ip=list(map(bin,list(map(int,input().split('.'))))) #print(ip) ip1=[] for i in ip: s='' if len(i)-2<8: s += '0'*(8-len(i)+2)+i[2:] ip1.append(s) else: ip1.append(i[2:]) #print(ip1) print(int(''.join(ip1),2)) ip_int=bin(int(input()))[2:] #print(ip_int,len(ip_int),type(ip_int)) if len(ip_int)%8!=0: ip_int = '0'*(8-len(ip_int)%8)+ip_int #print(ip_int) ip_int1=[] for i in range(4): #print(ip_int[i*8:(i+1)*8]) ip_int1.append(str(int(ip_int[i*8:(i+1)*8],2))) print('.'.join(ip_int1))