CyrusBuilt.MonoPi.BitSet.PreviousClearBit C# (CSharp) Method

PreviousClearBit() public method

Returns the index of the nearest bit that is set to false that occurs on or before the specified starting index.
/// cannot be less than zero. ///
public PreviousClearBit ( Int32 fromIndex ) : Int32
fromIndex System.Int32 /// The index to start checking from (inclusive). ///
return System.Int32
		public Int32 PreviousClearBit(Int32 fromIndex) {
			if (fromIndex < 0) {
				if (fromIndex == -1) {
					return -1;
				}
				throw new IndexOutOfRangeException("fromIndex cannot be less than zero.");
			}

			this.CheckInvariants();
			Int32 offset = WordIndex(fromIndex);
			if (offset >= this._wordsInUse) {
				return fromIndex;
			}

			Int32 result = -1;
			long w = ~this._bits[offset] & (LONG_MASK >> -(fromIndex + 1));
			while (true) {
				if (w != 0) {
					result = (offset + 1) * BITS_PER_WORD - 1 - NumberOfTrailingZeros(w);
					break;
				}

				if (offset-- == 0) {
					break;
				}
				w = ~this._bits[offset];
			}
			return result;
		}