Abinary gapwithin 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, number 9 has binary representation1001and contains a binary gap of length 2. The number 529 has binary representation1000010001and contains two binary gaps: one of length 4 and one of length 3. The number 20 has binary representation10100and contains one binary gap of length 1. The number 15 has binary representation1111and has no binary gaps.
bin_list = 
flag =Falsewhile(N >0):
if N %2==0:
N = N //2for i in bin_list:
if i ==1:
flag =Trueif (bin_gap > pre_gap):
pre_gap = bin_gap
bin_gap =0elif (i ==0and flag isTrue):