1. unsigned long in java, using BigInteger for arithmetics, but BigInteger.toByteArray returns 14 bytes instead of 8 stackoverflow.comI have the following c code which id like to port to Java
|
2. BigInteger.toByteArray coderanch.comHi Prosenjit, Here's an example. import java.math.BigInteger; public class BigInt { public static void main(String[] args) { byte[] b1 = { 0x1, 0 }; byte[] b2 = new byte[] { (byte) 128 }; BigInteger bi1 = new BigInteger( b1 ); BigInteger bi2 = new BigInteger( b2 ); byte[] b3 = bi1.toByteArray(); byte[] b4 = bi2.toByteArray(); } } Hope that helps. I'm ... |
3. Getting stuck with BigInteger.toByteArray forums.oracle.comThe javadoc for toByteArray says: "Returns a byte array containing the two's-complement representation of this BigInteger. The byte array will be in big-endian byte-order: the most significant byte is in the zeroth element. The array will contain the minimum number of bytes required to represent this BigInteger, including at least one sign bit" The byte that you see as zero is ... |