题解 | #求最大连续bit数#
求最大连续bit数
https://www.nowcoder.com/practice/4b1658fd8ffb4217bc3b7e85a38cfaf2
n = int(input()) list1 = list(bin(n)[2:]) # 转换成二进制字符串0b开头,oct()八进制0o开头,hex()十六进制 0x开头 length = len(list1) def islianxu(s): for i in s: if i != '1': return False return True max = 1 for i in range(length): for j in range(length): if islianxu(list1[i:j+1]): if max < j - i + 1: max = j - i + 1 print(max)