def ehex(n, width=0, padding=None):
    """
    Convert a number into "extended hex".
    
    Returns the extended hex presentation for N, optionally padding it
    up to WIDTH with PADDING.
    """
    ehex_digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    result = ''

    while n > 0:
        result = ehex_digits[n % len(ehex_digits)] + result
        n = n // len(ehex_digits)
        width -= 1
        continue

    # Pad if requested to do so.
    if padding != None:
        while width > 0:
            result = str(padding) + result
            width -= 1
            continue
        pass

    return result