CompUInt128 implements CompUInt<UInt64, UInt64, CompUInt128> { @Override public byte[] toByteArray() { byte[] bytes = new byte[16]; toByteArray(bytes, 0, low); toByteArray(bytes, 4, mid); toByteArrayLong(bytes, 8, high); return bytes; } CompUInt128(byte[] bytes);  CompUInt128(byte[] bytes, boolean requiresPadding);  CompUInt128(BigInteger value);   CompUInt128(long high, int mid, int low);   CompUInt128(UInt64 value);   CompUInt128(long value);   CompUInt128(CompUInt128 other); @Override CompUInt128 add(CompUInt128 other); @Override CompUInt128 multiply(CompUInt128 other); @Override CompUInt128 subtract(CompUInt128 other); @Override CompUInt128 negateUInt(); @Override boolean isZero(); @Override BigInteger toBigInteger(); @Override UInt64 getLeastSignificant(); @Override UInt64 getMostSignificant(); @Override UInt64 getLeastSignificantAsHigh(); @Override long toLong(); @Override int toInt(); @Override CompUInt128 shiftLowIntoHigh(); @Override int getLowBitLength(); @Override int getHighBitLength(); @Override String toString(); @Override byte[] toByteArray();  }
@Test public void testToByteArrayWithPadding() { byte[] bytes = new byte[]{0x42}; UInt<CompUInt128> uint = new CompUInt128(bytes, true); byte[] expected = new byte[16]; expected[expected.length - 1] = 0x42; byte[] actual = uint.toByteArray(); assertArrayEquals(expected, actual); }
@Test public void testToByteArray() { byte[] bytes = new byte[16]; new Random(1).nextBytes(bytes); UInt<CompUInt128> uint = new CompUInt128(bytes); byte[] actual = uint.toByteArray(); assertArrayEquals(bytes, actual); }
@Test public void testToByteArrayMore() { byte[] bytes = new byte[]{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x02, 0x03 }; UInt<CompUInt128> uint = new CompUInt128(bytes); byte[] actual = uint.toByteArray(); assertArrayEquals(bytes, actual); }