@Test public void success_toMutualOppositeForm() { BigInteger integer1 = new BigInteger("27"); BigInteger integer2 = new BigInteger("11"); BigInteger integer3 = new BigInteger("247"); BigInteger integer4 = new BigInteger("327"); int[] result1 = ArrayUtils.toMutualOppositeForm(integer1); int[] result2 = ArrayUtils.toMutualOppositeForm(integer2); int[] result3 = ArrayUtils.toMutualOppositeForm(integer3); int[] result4 = ArrayUtils.toMutualOppositeForm(integer4); assertThat(result1, is(new int[]{1, 0, -1, 1, 0, -1})); assertThat(result2, is(new int[]{1, -1, 1, 0, -1})); assertThat(result3, is(new int[]{1, 0, 0, 0, -1, 1, 0, 0, -1})); assertThat(result4, is(new int[]{1, -1, 1, -1, 0, 0, 1, 0, 0, -1})); }
public static int[] toMutualOppositeForm(BigInteger integer) { int[] binaryArray = toBinaryArray(integer); int binaryLength = binaryArray.length; int[] ternaryArray = new int[binaryLength + 1]; ternaryArray[0] = binaryArray[0]; for (int i = 1; i < binaryLength; i++) { ternaryArray[i] = binaryArray[i] - binaryArray[i - 1]; } ternaryArray[binaryLength] = -binaryArray[binaryLength - 1]; return ternaryArray; }
ArrayUtils { public static int[] toMutualOppositeForm(BigInteger integer) { int[] binaryArray = toBinaryArray(integer); int binaryLength = binaryArray.length; int[] ternaryArray = new int[binaryLength + 1]; ternaryArray[0] = binaryArray[0]; for (int i = 1; i < binaryLength; i++) { ternaryArray[i] = binaryArray[i] - binaryArray[i - 1]; } ternaryArray[binaryLength] = -binaryArray[binaryLength - 1]; return ternaryArray; } }
ArrayUtils { public static int[] toMutualOppositeForm(BigInteger integer) { int[] binaryArray = toBinaryArray(integer); int binaryLength = binaryArray.length; int[] ternaryArray = new int[binaryLength + 1]; ternaryArray[0] = binaryArray[0]; for (int i = 1; i < binaryLength; i++) { ternaryArray[i] = binaryArray[i] - binaryArray[i - 1]; } ternaryArray[binaryLength] = -binaryArray[binaryLength - 1]; return ternaryArray; }  }
ArrayUtils { public static int[] toMutualOppositeForm(BigInteger integer) { int[] binaryArray = toBinaryArray(integer); int binaryLength = binaryArray.length; int[] ternaryArray = new int[binaryLength + 1]; ternaryArray[0] = binaryArray[0]; for (int i = 1; i < binaryLength; i++) { ternaryArray[i] = binaryArray[i] - binaryArray[i - 1]; } ternaryArray[binaryLength] = -binaryArray[binaryLength - 1]; return ternaryArray; }  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); }
ArrayUtils { public static int[] toMutualOppositeForm(BigInteger integer) { int[] binaryArray = toBinaryArray(integer); int binaryLength = binaryArray.length; int[] ternaryArray = new int[binaryLength + 1]; ternaryArray[0] = binaryArray[0]; for (int i = 1; i < binaryLength; i++) { ternaryArray[i] = binaryArray[i] - binaryArray[i - 1]; } ternaryArray[binaryLength] = -binaryArray[binaryLength - 1]; return ternaryArray; }  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);  }