def dq_has_flag(dqf, flag_to_check):
    """
    Returns true/false if the given DQ value has a specific flag value set after
    unpacked into a 16-bit string.  For example:

    .. code-block:: python

         print dq_has_flag(48,16)
         True
         print dq_has_flag(40, 16)
         False

    :param dqf: The DQ value.

    :type dqf: int

    :param flag_to_check: The flag value to check if it's set to True.

    :type flag_to_check: int

    :returns: bool -- Returns True if `flag_to_check` is `True` inside `dqf`.

    :raises: ValueError
    """
    if flag_to_check & flag_to_check - 1 == 0 and flag_to_check != 0:
        dq_16bit_str = '{0:b}'.format(dqf)
        flag_16bit_str = '{0:b}'.format(flag_to_check)
        return len(flag_16bit_str) <= len(dq_16bit_str) and dq_16bit_str[-1 *
            len(flag_16bit_str)] == '1'
    else:
        raise ValueError(
            'Flag to check must be a power of 2.  Asked to check whether flag '
             + str(flag_to_check) + ' is set to True in bitmask value ' +
            str(dqf) + ', but ' + str(flag_to_check) + ' is not a power of 2.')
