Created
May 26, 2021 15:48
-
-
Save bharathmuddada/aa1d24bbaa24ebb1c372db1ab17cbbb8 to your computer and use it in GitHub Desktop.
Decimal to binary in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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