public static byte[] copy(final byte[] data, final int start, final int end) {
		if (start > end) {
			throw new IllegalArgumentException(String.format(
				"start > end: %d > %d", start, end
			));
		}
		if (start < 0 || start > data.length << 3) {
			throw new ArrayIndexOutOfBoundsException(String.format(
				"%d < 0 || %d > %d", start, start, data.length*8
			));
		}

		final int to = min(data.length << 3, end);
		final int byteStart = start >>> 3;
		final int bitStart = start & 7;
		final int bitLength = to - start;

		final byte[] copy = new byte[toByteLength(to - start)];

		if (copy.length > 0) {
			// Perform the byte wise right shift.
			System.arraycopy(data, byteStart, copy, 0, copy.length);

			// Do the remaining bit wise right shift.
			shiftRight(copy, bitStart);

			// Add the 'lost' bits from the next byte, if available.
			if (data.length > copy.length + byteStart) {
				copy[copy.length - 1] |= (byte)(data[byteStart + copy.length]
					<< (Byte.SIZE - bitStart));
			}

			// Trim (delete) the overhanging bits.
			copy[copy.length - 1] &= (byte)(0xFF >>> ((copy.length << 3) - bitLength));
		}

		return copy;
	}
Copies the specified range of the specified array into a new array.

@param data the bits from which a range is to be copied
@param start the initial index of the range to be copied, inclusive
@param end the final index of the range to be copied, exclusive.
@return a new array containing the specified range from the original array
@throws ArrayIndexOutOfBoundsException if start &lt; 0 or
        start &gt; data.length*8
@throws IllegalArgumentException if start &gt; end
@throws NullPointerException if the {@code data} array is
        {@code null}.
jenetics/src/main/java/io/jenetics/internal/util/Bits.java