toByteArray « biginteger « Java Data Type Q&A





1. unsigned long in java, using BigInteger for arithmetics, but BigInteger.toByteArray returns 14 bytes instead of 8    stackoverflow.com

I have the following c code which id like to port to Java

unsigned long long* data=(unsigned long long*)pBuffer; // file data
unsigned long long crypt = 0x0000;
unsigned long long next_crypt;
unsigned int len ...

2. BigInteger.toByteArray    coderanch.com

Hi 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.com

The 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 ...