题解 | #整数与IP地址间的转换#

整数与IP地址间的转换

https://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea

# 10.0.3.193
# 00001010 00000000 00000011 11000001
# 167773121
def ip_int(s):
   # s = list(map(int,input().split('.')))
    ss =''
    for i in s:
        ss += bin(i)[2:].zfill(8)

    return int(ss,2)
# 167969729
# 10.3.3.193
def int_ip(x):
    #x = int(input())    # 167969729
    ls = []
    xx = bin(x)[2:].zfill(32)
    for i in range(0,len(xx),8):
        ls.append(int(xx[i:i+8],2))
    lst = list(map(str,ls))
    res = ('.'.join(lst))
    return res

s = list(map(int,input().split('.')))   # 10.0.3.193
x = int(input())    # 167969729
print(ip_int(s))
print(int_ip(x))



全部评论

相关推荐

03-19 09:58
河海大学 Java
最喜欢春天的奇亚籽很...:同学,是小红书不是小哄书,一眼就能看到的错误
投了多少份简历才上岸
点赞 评论 收藏
分享
03-02 08:18
集美大学 Java
钱嘛数字而已:没有赛事奖项么?另外,项目经历字有点多哈,建议突出一下重点:用的什么技术,解决什么问题,达到什么效果。
大家都开始春招面试了吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务