Java BigInteger Calculate parseBinaryBigInteger(final byte[] buffer, final int offset, final int length, final boolean negative)

Here you can find the source of parseBinaryBigInteger(final byte[] buffer, final int offset, final int length, final boolean negative)

Description

parse Binary Big Integer

License

Apache License

Declaration

private static long parseBinaryBigInteger(final byte[] buffer, final int offset, final int length,
            final boolean negative) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.math.BigInteger;

public class Main {
    private static long parseBinaryBigInteger(final byte[] buffer, final int offset, final int length,
            final boolean negative) {
        byte[] remainder = new byte[length - 1];
        System.arraycopy(buffer, offset + 1, remainder, 0, length - 1);
        BigInteger val = new BigInteger(remainder);
        if (negative) {
            // 2's complement
            val = val.add(BigInteger.valueOf(-1)).not();
        }/*from w  ww  .  j  a v a2 s.  c om*/
        if (val.bitLength() > 63) {
            throw new IllegalArgumentException("At offset " + offset + ", " + length + " byte binary number"
                    + " exceeds maximum signed long" + " value");
        }
        return negative ? -val.longValue() : val.longValue();
    }
}

Related

  1. normalizarParaBigInteger(Number numero, RoundingMode modo)
  2. numberToIpv4(BigInteger ipNumber)
  3. numberToShortString(BigInteger number)
  4. order(BigInteger a, BigInteger p, BigInteger f[], BigInteger e[])
  5. parseBigInteger(String s, BigInteger defaultValue)
  6. parseScaledNonNegativeBigInteger(String str)
  7. product(final BigInteger min, final BigInteger max)
  8. randomFromZn(BigInteger n, Random rand)
  9. removeDuplicates(final BigInteger... values)