public void swapSubstring ( BitString other , int start , int length ) { assertValidIndex ( start ) ; other . assertValidIndex ( start ) ; int word = start / WORD_LENGTH ; int partialWordSize = ( WORD_LENGTH - start ) % WORD_LENGTH ; if ( partialWordSize > 0 ) { swapBits ( other , word , 0xFFFFFFFF << ( WORD_LENGTH - partialWordSize ) ) ; ++ word ; } int remainingBits = length - partialWordSize ; int stop = remainingBits / WORD_LENGTH ; for ( int i = word ; i < stop ; i ++ ) { int temp = data [ i ] ; data [ i ] = other . data [ i ] ; other . data [ i ] = temp ; } remainingBits %= WORD_LENGTH ; if ( remainingBits > 0 ) { swapBits ( other , word , 0xFFFFFFFF >>> ( WORD_LENGTH - remainingBits ) ) ; } }
An efficient method for exchanging data between two bit strings . Both bit strings must be long enough that they contain the full length of the specified substring .