def dec2hex(n, uni=1):
    """Convert decimal number to hex string with 4 digits, and more digits if
    the number is larger.

    >>> dec2hex(12)
    '000C'
    >>> dec2hex(100)
    '0064'
    >>> dec2hex(65535)
    'FFFF'
    >>> dec2hex(100000)
    '186A0'
    """
    hexadec = '%X' % n
    if uni == 1:
        while len(hexadec) <= 3:
            hexadec = '0' + str(hexadec)
    return hexadec
