-
-
Save mvallebr/3d4dbfaebd6a219575a793ab3778ba70 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 = [] | |
zero = '0' | |
while num > 0: | |
num, bit = divmod(num, 2) | |
result.append(bit) | |
zero = '' | |
# Imprimir em ordem inversa | |
print(zero + "".join(map(str, result))[::-1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment