def calculate_value(mask, value):
    """ Calculates value with mask applied.

    :param mask: mask string
    :param value: int value
    :return: int value
    """
    # get binary value as string
    bin_value = '{0:036b}'.format(value)

    # replace all values except X
    for i in range(len(mask)):
        if mask[i] != 'X':
            bin_value = bin_value[:i] + mask[i] + bin_value[i+1:]

    return int(str(bin_value), 2)