Convert BigInteger to unsigned long in Java

BigInteger.longValue() throws away all but the lowest 64 bits.

BigInteger bigInteger = BigInteger.valueOf(Long.MAX_VALUE)
                                  .add(BigInteger.valueOf(24193));
long lng = bigInteger.longValue();

System.out.println(Long.toUnsignedString(lng));  // 9223372036854800000

Comments

Be the first to comment!