Skip to content

Instantly share code, notes, and snippets.

@dcortesnet
Created February 12, 2024 00:31
Show Gist options
  • Save dcortesnet/ca5305f6f6656c25606cf78892731410 to your computer and use it in GitHub Desktop.
Save dcortesnet/ca5305f6f6656c25606cf78892731410 to your computer and use it in GitHub Desktop.
Python convertir un número en los diferentes sistemas númericos
# Contrains 1 <= n <= 99
def print_formatted(number: int):
width = len(bin(number)[2:])
for n in range(1, number +1):
decimal = n
octal = oct(n)[2:]
hexadecimal = hex(n)[2:].upper()
binary = bin(n)[2:]
print("{0:>{width}} {1:>{width}} {2:>{width}} {3:>{width}}".format(decimal, octal, hexadecimal, binary, width=width))
print_formatted(17)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment