Created
July 24, 2019 22:03
-
-
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.
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): | |
| 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