Skip to content

Instantly share code, notes, and snippets.

@haithamsha
Created July 24, 2019 22:03
Show Gist options
  • Save haithamsha/cf498596769b6a8c538eb68c2d119d5d to your computer and use it in GitHub Desktop.
Save haithamsha/cf498596769b6a8c538eb68c2d119d5d to your computer and use it in GitHub Desktop.
Convert decimal to binary with python, there is not the perfect solution trying to enhance it.
def decToBinary(n):
mod = ""
n = int(n)
while n>0:
result = int(n/2)
mod = str(mod) + str(n%2)
n = int(result)
return mod
print(decToBinary(10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment