Skip to content

Commit

Permalink
Reto #14 - Python
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoatrs committed Aug 6, 2023
1 parent d1b8384 commit 0a8f641
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Retos/Reto #14 - OCTAL Y HEXADECIMAL [Fácil]/python/marcoatrs.py
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit 0a8f641

Please sign in to comment.