Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.2 kB
0
Indexable
Never

def to_binary(n):
    reminders = []
    while n > 0:
        reminder = n % 2
        reminders.append(reminder)
        n = n // 2
    reminders.reverse()
    return reminders
print(to_binary(14))
def to_oct(n):
    reminders = []
    while n>=0:
        reminder = n%8
        reminders.append(reminder)
        n=n//8
    reminders.reverse()
    return reminders
print(to_oct(13))
def to_hex(n):
    reminders = []
    while n >= 0:
        reminder = n % 16
        n=n//16
        if 0 <= reminder <= 9:
            reminders.append(reminder)
        elif reminder == 10:
            reminders.append("a")
        elif reminder == 11:
            reminders.append("b")
        elif reminder == 12:
            reminders.append("c")
        elif reminder == 13:
            reminders.append("d")
        elif reminder == 14:
            reminders.append("e")
        elif reminder == 15:
            reminders.append("f")
        elif reminder == 16:
            reminders.append("g")
    reminders.reverse()
    return reminders
print(to_hex(14))
def zamiana(n):
    n=number
    return n
print("wpisz liczbę:",n)
print(to_binary(n))
print(to_hex(n))
Leave a Comment