Bits { public static byte[] shiftLeft(final byte[] data, final int shift) { final int bytes = min(shift >>> 3, data.length); final int bits = shift & 7; if (bytes > 0) { for (int i = 0, n = data.length - bytes; i < n; ++i) { data[data.length - 1 - i] = data[data.length - 1 - i - bytes]; } for (int i = 0; i < bytes; ++i) { data[i] = (byte)0; } } if (bits > 0 && bytes < data.length) { int carry = 0; int nextCarry = 0; for (int i = bytes; i < data.length; ++i) { int d = data[i] & 0xFF; nextCarry = d >>> (Byte.SIZE - bits); d <<= bits; d |= carry; data[i] = (byte)(d & 0xFF); carry = nextCarry; } } return data; } 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(dataProvider = "shiftBits") public void shiftLeft(final Integer shift, final Integer bytes) { final long seed = System.currentTimeMillis(); final Random random = new Random(seed); final byte[] data = new byte[bytes]; for (int i = 0; i < data.length*8; ++i) { Bits.set(data, i, random.nextBoolean()); } Bits.shiftLeft(data, shift); random.setSeed(seed); for (int i = 0; i < shift; ++i) { Assert.assertEquals(Bits.get(data, i), false); } for (int i = shift, n = data.length*8; i < n; ++i) { Assert.assertEquals(Bits.get(data, i), random.nextBoolean(), "Index: " + i); } }