I convert bigints to binary, radix16 and radix64 encoding and see the mysterious msb zero bursts. Is this a big problem that I can solve by removing the zero padding, or possibly doing something else?
My test code is:
String s; System.out.printf( "%s length %d\n", s = "123456789A", (new BigInteger( s, 16 )).toByteArray().length ); System.out.printf( "%s length %d\n", s = "F23456789A", (new BigInteger( s, 16 )).toByteArray().length );
Outputs:
123456789A length 5 F23456789A length 6
Of which a longer array has zero padding forward. After checking BigInteger.toByteArray () I see:
public byte[] toByteArray() { int byteLen = bitLength()/8 + 1; byte[] byteArray = new byte[byteLen];
Now I can find private int bitLength; but I can't find where the Length () bit is defined to pinpoint why this class does this - possibly related to sign extension?
user968363
source share