题解 | #整数与IP地址间的转换#Python 位运算
整数与IP地址间的转换
https://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea
直接位运算,用掩码消掉前缀:
a = list(map(int,input().split('.'))) b = int(input()) print((a[0]<<24) + (a[1]<<16) + (a[2]<<8) + a[3]) resb = [] resb.append(str(b>>24)) resb.append(str(b>>16 & 0xff)) resb.append(str(b>>8 & 0xff)) resb.append(str(b & 0xff)) print('.'.join(resb))