def int_to_hexstring(data, data_type='H', str_len=8):
    """
    Takes an integer and creates a hex string of the appropriate length
        Args:
            data (int): value to hexlify
            data_type (int): one of the enumerated TAGTYPES
            str_len (int): number of characters in the resulting string
        Returns:
            hexstring of the data
    """

    if data_type in ('B', 'b'):
        fmt1 = '{:0>2}'
    elif data_type in ('H', 'h'):
        fmt1 = '{:0>4}'
    elif data_type in ('I', 'i'):
        fmt1 = '{:0>8}'
    elif data_type in ('R'):
        fmt1 = '{:0>16}'
    else:
        fmt1 = "{:0>4}"
    fmt2 = '{:0<' + str(int(str_len)) + '}'

    hexstring = fmt2.format(fmt1.format(hex(data)[2:]))

    return hexstring