Take the 2-minute tour ×
BigInteger bx=new BigInteger("5888561920");


byte x[]=new byte[5];






        System.out.print(" "+t[i]);

System.out.println("\nbig: "+toInt(t));

The output for the above code is:


 94 -4 83 0

big: 1593594624

The problem here is when i am converting a big integer into a byte array and again converting the same byte array to a big integer, the values of big integer are changing. But when i replace the number "5888561920" with "2944280960" or "3806908688" there is no problem i am getting the same number as output. What is the problem here? Is the problem with BigInteger or "5888561920"

I have written the toInt method myself:

public static BigInteger toInt(byte[] b){

     String st=new String();
    for(int k=3;k>=0;k--){
            if ((b[k] & 0x01) == 1)
            b[k]=  (byte) (b[k] >> 1);

    BigInteger bi=new BigInteger(st,2);

    return bi;
share|improve this question
I think this is the problem with boundary of int or long check for numbers above 2^32 and below 2^32 –  RAVITEJA SATYAVADA Aug 5 '11 at 6:07

2 Answers 2

up vote 2 down vote accepted

In toInt(), you're concatenating the 32 least significant bits (k=0..3 x i=0..7) of the number.

5888561920 is larger than a 32-bit number. In fact its binary representation (according to Windows Calc) is 101011110111111000101001100000000, which is 33 bits long. You've truncated the most significant bit.

2944280960 and 3806908688 fit within 32 bits (bits 33 and beyond would all be zeroes anyway).

So I guess you do need that fifth byte, after all : )

share|improve this answer

The lower 4 bytes of 5888561920 is (5888561920 % 2^32) == 1593594624

If you want to store this number you need more than 4 bytes.

share|improve this answer

Your Answer


