我正在尝试使用with将 aLargeInteger
转换为byte[]
长度未知的 abitLength()
static byte[] encodeint(LargeInteger y) {
//byte[] in = y.toByteArray();
byte[] in = new byte[(int)Math.ceil((double)y.bitLength() / 8.0)];
y.toByteArray(in, 0);
//
byte[] out = new byte[in.length];
for (int i=0;i<in.length;i++) {
out[i] = in[in.length-1-i];
}
return out;
}
但执行人返回
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
指向y.toByteArray(in, 0);
.
如何in
正确设置长度?
(注释的代码是转换后的BigInteger
代码留下的。)