Created
August 4, 2014 14:19
-
-
Save fmasanori/f364c6baf2c7bea1c96e to your computer and use it in GitHub Desktop.
Decimal para binário em Python 3
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 dec2bin(n): | |
b = '' | |
while n != 0: | |
b = b + str(n % 2) | |
n = int(n / 2) | |
return b[::-1] | |
def d2b(n): | |
if n == 0: | |
return '' | |
else: | |
return d2b(n//2) + str(n%2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sensacional!