import string

def to_base(num, b):
    result = ''
    alphabet = string.digits + string.ascii_uppercase
    if num == 0:
        return alphabet[0]  # Return '0' if number is zero
    while num > 0:
        i = num % b
        num = num // b
        result = alphabet[i] + result
    return result.upper()  # Ensuring the output is consistently in uppercase, as per typical base conversion representation.