byte[] to unsigned BigInteger?
Examining the documentation for the relevant BigInteger
constructor, we see:
The individual bytes in the value array should be in little-endian order, from lowest-order byte to highest-order byte
[...]
The constructor expects positive values in the byte array to use sign-and-magnitude representation, and negative values to use two's complement representation. In other words, if the highest-order bit of the highest-order byte in value is set, the resulting BigInteger value is negative. Depending on the source of the byte array, this may cause a positive value to be misinterpreted as a negative value.
[...]
To prevent positive values from being misinterpreted as negative values, you can add a zero-byte value to the end of the array.
The remarks for the BigInteger
constructor state that you can make sure any BigInteger
created from a byte[]
is unsigned if you append a 00
byte to the end of the array before calling the constructor.
Note: the BigInteger
constructor expects the array to be in little-endian order. Keep that in mind if you expect the resulting BigInteger
to have a particular value.