-
-
Save parzibyte/b55270307b50dd981fd7720e7b687aed to your computer and use it in GitHub Desktop.
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
""" | |
https://parzibyte.me/blog | |
""" | |
def decimal_a_binario(decimal): | |
if decimal <= 0: | |
return "0" | |
# Aquí almacenamos el resultado | |
binario = "" | |
# Mientras se pueda dividir... | |
while decimal > 0: | |
# Saber si es 1 o 0 | |
residuo = int(decimal % 2) | |
# E ir dividiendo el decimal | |
decimal = int(decimal / 2) | |
# Ir agregando el número (1 o 0) a la izquierda del resultado | |
binario = str(residuo) + binario | |
return binario | |
decimal = int(input("Ingresa un número decimal: ")) | |
binario = decimal_a_binario(decimal) | |
print(f"El número {decimal} es {binario} en binario") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment