Skip to content

Instantly share code, notes, and snippets.

@mvallebr
Forked from echiesse/binConverter.py
Last active June 22, 2017 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mvallebr/3d4dbfaebd6a219575a793ab3778ba70 to your computer and use it in GitHub Desktop.
Save mvallebr/3d4dbfaebd6a219575a793ab3778ba70 to your computer and use it in GitHub Desktop.
Exemplo de conversão de decimal para binário
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