题解 | #整数与IP地址间的转换#
整数与IP地址间的转换
http://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea
import sys while True: try: ips = list(map(int, input().split('.'))) sum_ip = 0 for ip in ips: sum_ip = ip + (sum_ip << 8) print(sum_ip) sum_ip = int(input()) ips = [0,0,0,0] for i in range(4): ips[4 - 1 - i] = str(sum_ip % (2**8)) sum_ip = (sum_ip >> 8) print('.'.join(ips)) except: # print(sys.exc_info()) break