Last active
October 18, 2017 18:41
-
-
Save echiesse/52bfc9663f92c6825d9d84ad2573a7cf to your computer and use it in GitHub Desktop.
Exemplo de conversão de decimal para binário
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
num = int(input("Escolha um número decimal para transformar em binario: ")) | |
result = [] | |
while num >= 1: | |
bit = num % 2 | |
result.append(bit) | |
num = int(num/2) | |
# Imprimir em ordem inversa | |
print("".join(map(str, result))[::-1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment