Bits { public static void swap( final byte[] data, final int start, final int end, final byte[] otherData, final int otherStart ) { for (int i = end - start; --i >= 0;) { final boolean temp = get(data, i + start); set(data, i + start, get(otherData, otherStart + i)); set(otherData, otherStart + i, temp); } } private  Bits(); static boolean get(final byte[] data, final int index); static byte[] set(
		final byte[] data,
		final int index,
		final boolean value
	); static byte[] set(final byte[] data, final int index); static byte[] unset(final byte[] data, final int index); static void swap(
		final byte[] data, final int start, final int end,
		final byte[] otherData, final int otherStart
	); static int count(final byte[] data); static int count(final byte value); static byte[] shiftRight(final byte[] data, final int shift); static byte[] shiftLeft(final byte[] data, final int shift); static byte[] increment(final byte[] data); static byte[] invert(final byte[] data); static byte[] complement(final byte[] data); static byte[] flip(final byte[] data, final int index); static byte[] reverse(final byte[] array); static byte[] copy(final byte[] data, final int start, final int end); static boolean getAndSet(final byte[] array, final int index); static String toByteString(final byte... data); static byte[] fromByteString(final String data); static byte[] newArray(final int length); static byte[] newArray(final int length, final double p); static int toByteLength(final int bitLength); static int toInt(final byte[] data); static byte[] toBytes(final int value); static long toLong(final byte[] data); static byte[] toBytes(final long value);  }
@Test public void swap() { final int byteLength = 1_000; final int bitLength = byteLength*8; final byte[] seq = newByteArray(byteLength, new Random()); for (int start = 0; start < bitLength - 3; ++start) { final byte[] copy = seq.clone(); final byte[] other = newByteArray(byteLength, new Random()); final byte[] otherCopy = other.clone(); final int end = start + 2; final int otherStart = 1; Bits.swap(seq, start, end, other, otherStart); for (int j = start; j < end; ++j) { final boolean actual = Bits.get(seq, j); final boolean expected = Bits.get(otherCopy, j + otherStart - start); Assert.assertEquals(actual, expected); } for (int j = 0; j < (end - start); ++j) { final boolean actual = Bits.get(other, j + otherStart); final boolean expected = Bits.get(copy, j + start); Assert.assertEquals(actual, expected); } } }