public void setRange ( int start , int end ) { if ( end < start || start < 0 || end > size ) { throw new IllegalArgumentException ( ) ; } if ( end == start ) { return ; } 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 ) ; bits [ i ] |= mask ; } }
Sets a range of bits .