Created
September 1, 2017 13:38
-
-
Save Mdslino/6fbb5ef232741028e1b542d1a2667471 to your computer and use it in GitHub Desktop.
Conversão de Bases
This file contains 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
# Conversão de Binário para decimal | |
num = input('Digite o número binário: ') | |
resultado = [] | |
for i in range(len(num)): | |
if int(num[::-1][i]) == 1: | |
resultado += 2 ** i | |
print(resultado) | |
#Conversão de Decimal para binário | |
num = int(input("Digite o número decimal: ")) | |
binario = '' | |
while True: | |
binario += str(0 if num % 2 == 0 else 1) | |
num //= 2 | |
if num == 0: | |
break | |
print(binario[::-1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment