ArrayUtils { public static int[] toBinaryArray(BigInteger integer) { byte[] tmp = integer.toByteArray(); int[] array = new int[tmp.length * 8]; for (int i = 0; i < tmp.length; i++) { for (int j = 0; j < 8; j++) { array[i * 8 + j] = (tmp[i] & 0x80) / 0x80; tmp[i] <<= 1; } } int count = 0; for (int anArray : array) { if (anArray == 1) { break; } else { count++; } } int[] result = new int[array.length - count]; System.arraycopy(array, count, result, 0, result.length); return result; }  static byte[][] split(byte[] bytes, int splitIndex); static int[] reverse(int[] input); static byte[] toByteArray(BigInteger value, int expectedBytesLength); static int[] toBinaryArray(BigInteger integer); static int[] toMutualOppositeForm(BigInteger integer);  }
@Test public void success_toBinaryArray() { BigInteger integer = new BigInteger("2"); BigInteger integer1 = new BigInteger("17"); BigInteger integer2 = new BigInteger("257"); BigInteger integer3 = new BigInteger("256"); int[] result = ArrayUtils.toBinaryArray(integer); int[] result1 = ArrayUtils.toBinaryArray(integer1); int[] result2 = ArrayUtils.toBinaryArray(integer2); int[] result3 = ArrayUtils.toBinaryArray(integer3); assertThat(result, is(new int[]{1, 0})); assertThat(result1, is(new int[]{1, 0, 0, 0, 1})); assertThat(result2, is(new int[]{1, 0, 0, 0, 0, 0, 0, 0, 1})); assertThat(result3, is(new int[]{1, 0, 0, 0, 0, 0, 0, 0, 0})); }