Skip to content

Instantly share code, notes, and snippets.

@Weizhang2017
Created October 11, 2019 02:13
Show Gist options
  • Save Weizhang2017/d78a30bb45007af1eaf0424e9773e2ef to your computer and use it in GitHub Desktop.
Save Weizhang2017/d78a30bb45007af1eaf0424e9773e2ef to your computer and use it in GitHub Desktop.
Calculate the largest number of zeros between ones in a binary number
def conver_to_binary(N):
remainder = list()
quotient = N // 2
remainder.append(quotient%2)
while quotient > 0:
remainder.append(quotient%2)
quotient = quotient // 2
return remainder[::-1]
binary = conver_to_binary(N)
zeros = 0
length = 0
for value in binary:
if value == 1:
if zeros > length:
length = zeros
zeros = 0
else:
zeros += 1
return length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment