From 0a8f641934e51a13ccf558a76001220fa77eb686 Mon Sep 17 00:00:00 2001 From: Marco Torres Date: Sat, 5 Aug 2023 23:43:34 -0700 Subject: [PATCH] Reto #14 - Python --- .../python/marcoatrs.py" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "Retos/Reto #14 - OCTAL Y HEXADECIMAL [F\303\241cil]/python/marcoatrs.py" diff --git "a/Retos/Reto #14 - OCTAL Y HEXADECIMAL [F\303\241cil]/python/marcoatrs.py" "b/Retos/Reto #14 - OCTAL Y HEXADECIMAL [F\303\241cil]/python/marcoatrs.py" new file mode 100644 index 0000000000..0eaa0db1ae --- /dev/null +++ "b/Retos/Reto #14 - OCTAL Y HEXADECIMAL [F\303\241cil]/python/marcoatrs.py" @@ -0,0 +1,24 @@ +def dec2hexa(num: int) -> str: + replaces = {10: "A", 11: "B", 12: "C", 13: "D", 14: "E", 15: "F"} + hexa = [] + while num > 16: + hexa.insert(0, replaces.get((num % 16), str((num % 16)))) + num //= 16 + hexa.insert(0, replaces.get(num, str(num))) + return "".join(hexa) + + +def dec2oct(num: int) -> str: + oct = [] + while num > 8: + oct.insert(0, str(num % 8)) + num //= 8 + oct.insert(0, str(num)) + return "".join(oct) + + +def convert(num: int): + return dec2hexa(num), dec2oct(num) + + +print(convert(19489052815))