Contenido del Curso
Sistemas Numerales 101
Sistemas Numerales 101
Un Desafío de Cifrado Más
¡Aprecio mucho tus esfuerzos! Aquí vas a sumergirte más en el cifrado y tu último desafío es convertir un número del sistema numérico decimal a uno hexadecimal. Intenta hacerlo utilizando cadenas😉.
- Necesitas dividir el número por 16 y anotar el resto de la división.
- Si el número es mayor que 9, necesitas encontrar una equivalencia en letras.
- Luego debes calcular con el número obtenido y aplicarle el primer paso.
- Puedes parar si el resultado de la división es 0.
- Reescribe los restos en orden inverso.
# Implementing dictionary, but here the keys are numbers, because we are ciphering dictionary = {0: "0", 1: "1", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7", 8: "8", 9: "9", 10:"A" , 11:"B", 12:"C", 13:"D", 14:"E", 15:"F"} # Defining the decimal number 64206 decimal_number = 64206 # The text should be realised here due to the reason that further the decimal number will be changed print("The number in decimal numeral system is:", decimal_number) # Creating a list for storing converted hex number hexadecimal_number = [] # The conformity for 0 in decimal numeration system is 0; hence, this condition implemented # The loop executes till the number is zero while decimal_number != 0: # Counting the remainder of division by 16 remainder = decimal_number % 16 # Appending the converted resulting number for creating hexadecimal number hexadecimal_number.append(str(dictionary[remainder])) # This operation allows to decrease number by 16 an work with integer part of new one decimal_number = decimal_number // 16 # Reversing the string hexadecimal_number = hexadecimal_number[::-1] # Concatenating elements hexadecimal_number = "".join(hexadecimal_number) # Printing the result print("The number in hexadecimal numeral system is:", hexadecimal_number)
Swipe to start coding
¡Es hora de perfeccionar tus habilidades! Sigue el algoritmo y completa los espacios para recibir un número en representación hexadecimal:
- Imprime la variable
decimal_number
. - Crea una lista vacía para almacenar
hexadecimal_number
. - Define el bucle que se ejecuta hasta que el
decimal_number
sea0
. - Calcula el
resto
de la división dedecimal_number
por16
. - Invierte el string
hexadecimal_number
. - Une todos los elementos del string
hexadecimal_number
.
Solución
¡Gracias por tus comentarios!
Un Desafío de Cifrado Más
¡Aprecio mucho tus esfuerzos! Aquí vas a sumergirte más en el cifrado y tu último desafío es convertir un número del sistema numérico decimal a uno hexadecimal. Intenta hacerlo utilizando cadenas😉.
- Necesitas dividir el número por 16 y anotar el resto de la división.
- Si el número es mayor que 9, necesitas encontrar una equivalencia en letras.
- Luego debes calcular con el número obtenido y aplicarle el primer paso.
- Puedes parar si el resultado de la división es 0.
- Reescribe los restos en orden inverso.
# Implementing dictionary, but here the keys are numbers, because we are ciphering dictionary = {0: "0", 1: "1", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7", 8: "8", 9: "9", 10:"A" , 11:"B", 12:"C", 13:"D", 14:"E", 15:"F"} # Defining the decimal number 64206 decimal_number = 64206 # The text should be realised here due to the reason that further the decimal number will be changed print("The number in decimal numeral system is:", decimal_number) # Creating a list for storing converted hex number hexadecimal_number = [] # The conformity for 0 in decimal numeration system is 0; hence, this condition implemented # The loop executes till the number is zero while decimal_number != 0: # Counting the remainder of division by 16 remainder = decimal_number % 16 # Appending the converted resulting number for creating hexadecimal number hexadecimal_number.append(str(dictionary[remainder])) # This operation allows to decrease number by 16 an work with integer part of new one decimal_number = decimal_number // 16 # Reversing the string hexadecimal_number = hexadecimal_number[::-1] # Concatenating elements hexadecimal_number = "".join(hexadecimal_number) # Printing the result print("The number in hexadecimal numeral system is:", hexadecimal_number)
Swipe to start coding
¡Es hora de perfeccionar tus habilidades! Sigue el algoritmo y completa los espacios para recibir un número en representación hexadecimal:
- Imprime la variable
decimal_number
. - Crea una lista vacía para almacenar
hexadecimal_number
. - Define el bucle que se ejecuta hasta que el
decimal_number
sea0
. - Calcula el
resto
de la división dedecimal_number
por16
. - Invierte el string
hexadecimal_number
. - Une todos los elementos del string
hexadecimal_number
.
Solución
¡Gracias por tus comentarios!