Skip to content

Instantly share code, notes, and snippets.

@bharathmuddada
Created May 26, 2021 15:48
Show Gist options
  • Save bharathmuddada/aa1d24bbaa24ebb1c372db1ab17cbbb8 to your computer and use it in GitHub Desktop.
Save bharathmuddada/aa1d24bbaa24ebb1c372db1ab17cbbb8 to your computer and use it in GitHub Desktop.
Decimal to binary in python
def decToBinary(n):
if n==0:
return "0"
res =""
while n > 0:
res = res + str(n%2)
n = n//2
return res[::-1]
print(decToBinary(15))
'''output= 1111'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment