code: public boolean isRange(int start, int end, boolean value) {
      if (end < start || start < 0 || end > size) {
        throw new IllegalArgumentException();
      }
      if (end == start) {
        return true; // empty range matches
      }
      end--; // will be easier to treat this as the last actually set bit -- inclusive
      int firstInt = start / 32;
      int lastInt = end / 32;
      for (int i = firstInt; i <= lastInt; i++) {
        int firstBit = i > firstInt ? 0 : start & 0x1F;
        int lastBit = i < lastInt ? 31 : end & 0x1F;
        // Ones from firstBit to lastBit, inclusive
        int mask = (2 << lastBit) - (1 << firstBit);
  
        // Return false if we're looking for 1s and the masked bits[i] isn't all 1s (that is,
        // equals the mask, or we're looking for 0s and the masked portion is not all 0s
        if ((bits[i] & mask) != (value ? mask : 0)) {
          return false;
        }
      }
      return true;
    }
docs: Efficient method to check if a range of bits is set, or not set.
  
  @param start start of range, inclusive.
  @param end end of range, exclusive
  @param value if true, checks that bits in range are set, otherwise checks that they are not set
  @return true iff all bits are set or not set in range, according to value argument
  @throws IllegalArgumentException if end is less than start or the range is not contained in the array