def check_bit(val, n):
    """ Returns the value of the n-th (0 index) bit in given number """

    try:
        if val & 2**n:
            return 1
        else:
            return 0
    except TypeError:
        return -1