题解 | #整数与IP地址间的转换#
整数与IP地址间的转换
https://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea
ip = map(int, input().split('.')) de = int(input()) def ip_de(x): r1 = 0 for i in x: r1 = (r1 << 8) + i return(r1) def de_ip(y): r2 = [] for _ in range(4): r2.insert(0, str(y & 0xff)) y = y >> 8 return r2 print(ip_de(ip)) print('.'.join(de_ip(de))) # dec-move_left-dec # dec-extract_8bits-dec # bin(0) -> '0b0': 1. leading 0s are lost; 2. '0b' prefix; 3.