Un Nuevo Desafío de Cifrado
¡Aprecio mucho tus esfuerzos! Aquí vas a profundizar en el cifrado y la última cuestión para ti es convertir un número de un sistema numérico decimal a uno hexadecimal. Intenta hacerlo utilizando cadenas😉.
- Tienes que dividir el número entre 16 y anotar el resto de la división.
- Si el número es mayor que 9, necesitas encontrar una coincidencia en letras.
- Luego debes calcular el número recibido y aplicarle el primer paso.
- Puedes detenerte si la división da como resultado 0.
- Vuelva a escribir los restos en el orden inverso.
1234567891011121314151617181920212223# 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 rellena los huecos para recibir un número en representación hexadecimal:
- Imprime la variable
número_decimal
. -
- Crea una lista vacía para almacenar
número_hexadecimal
.
- Crea una lista vacía para almacenar
- Definir el bucle que se ejecuta hasta que el
número_decimal
es0
. - Contar el
resto
de la divisiónnúmero_decimal
por16
. - Hacer que la cadena
hexadecimal_number
se invierta. - Unir todos los elementos de la cadena
hexadecimal_number
.
Solución
¡Gracias por tus comentarios!
single
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Awesome!
Completion rate improved to 7.14
Un Nuevo Desafío de Cifrado
Desliza para mostrar el menú
¡Aprecio mucho tus esfuerzos! Aquí vas a profundizar en el cifrado y la última cuestión para ti es convertir un número de un sistema numérico decimal a uno hexadecimal. Intenta hacerlo utilizando cadenas😉.
- Tienes que dividir el número entre 16 y anotar el resto de la división.
- Si el número es mayor que 9, necesitas encontrar una coincidencia en letras.
- Luego debes calcular el número recibido y aplicarle el primer paso.
- Puedes detenerte si la división da como resultado 0.
- Vuelva a escribir los restos en el orden inverso.
1234567891011121314151617181920212223# 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 rellena los huecos para recibir un número en representación hexadecimal:
- Imprime la variable
número_decimal
. -
- Crea una lista vacía para almacenar
número_hexadecimal
.
- Crea una lista vacía para almacenar
- Definir el bucle que se ejecuta hasta que el
número_decimal
es0
. - Contar el
resto
de la divisiónnúmero_decimal
por16
. - Hacer que la cadena
hexadecimal_number
se invierta. - Unir todos los elementos de la cadena
hexadecimal_number
.
Solución
¡Gracias por tus comentarios!
Awesome!
Completion rate improved to 7.14single