I have to find the binary gap for an integer number.
A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.
For example: N = 1041 binary:10000010001 Result: 5 (5 zeros surrounded by ones)
Below is my code, although bin_no[22] is 1 but it never goes inside if statement.
def solution(N):
bin_no = f'{N:32b}'
print(len(bin_no))
count = []
for i in range(len(bin_no)):
if bin_no[i] == 1:
count[i] = 0
j=i
while(bin_no[j+1] != 1):
count[i] +=1
j +=1
print (count[i])
print(solution(529))