子网掩码

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)))
        
            

 

posted @ 2020-11-20 15:27  十方劫  阅读(79)  评论(0编辑  收藏  举报