其他分享
首页 > 其他分享> > 子网掩码

子网掩码

作者:互联网

1、产生2进制下连续的1的情况

ls=[]
for i in range(128,256):
    a=bin(i)[2:]
    ls1=''.join(a)
    for j in range(len(ls1)):
        if int(ls1[j]) == 0:
            ls2 = ls1[j:]
            sum = 0
            for k in ls2:
                sum += int(k)
            if sum > 0:
                break
            else:
                ls.append(i)
        else:
            continue
print(sorted(set(ls)))
        
            

 

标签:int,sum,else,ls2,ls,ls1,子网掩码
来源: https://www.cnblogs.com/lag1/p/14011133.html