Example usage for java.math BigInteger valueOf

List of usage examples for java.math BigInteger valueOf

Introduction

In this page you can find the example usage for java.math BigInteger valueOf.

Prototype

private static BigInteger valueOf(int val[]) 

Source Link

Document

Returns a BigInteger with the given two's complement representation.

Usage

From source file:Main.java

private static int gcd(int a, int b) {
    return BigInteger.valueOf((long) a).gcd(BigInteger.valueOf((long) b)).intValue();
}

From source file:Main.java

public static String bigInteger2str(BigInteger amount) {

    return (amount.divide((BigInteger.valueOf(100l)))).toString();
}

From source file:Main.java

public static BigInteger sqrt(final BigInteger val) {
    final BigInteger two = BigInteger.valueOf(2);
    BigInteger a = BigInteger.ONE.shiftLeft(val.bitLength() / 2);
    BigInteger b;//from   w w  w  .ja  va 2  s .  co  m
    do {
        b = val.divide(a);
        a = (a.add(b)).divide(two);
    } while (a.subtract(b).abs().compareTo(two) >= 0);
    return a;
}

From source file:Main.java

public static byte[] toBytes(long num) {
    BigInteger a = BigInteger.valueOf(num);
    byte[] temp = a.toByteArray();
    byte[] tr = new byte[temp.length];

    for (int i = 0; i < tr.length; i++) {
        tr[i] = temp[temp.length - 1 - i];
    }/*from   w w w  .  j a  va  2 s .  co m*/
    return tr;
}

From source file:Main.java

public static byte[] convertIntToByteArray(int arg) {
    BigInteger bigInt = BigInteger.valueOf(arg);
    return bigInt.toByteArray();
}

From source file:Main.java

public static String longToHex(long l) {
    return byteArrayToHex(BigInteger.valueOf(l).toByteArray(), null);
}

From source file:Main.java

public static String longToPrettyHex(long v) {
    return byteArrayToHex(BigInteger.valueOf(v).toByteArray(), " ");
}

From source file:Main.java

public static boolean isGoodGaAndGb(BigInteger g_a, BigInteger p) {
    return !(g_a.compareTo(BigInteger.valueOf(1)) != 1
            || g_a.compareTo(p.subtract(BigInteger.valueOf(1))) != -1);
}

From source file:Main.java

public static BigInteger sumOf(Collection<Integer> numbers) {
    BigInteger sum = BigInteger.ZERO;
    for (Integer n : numbers) {
        sum = sum.add(BigInteger.valueOf(n));
    }// w  ww  .  jav a  2s  .c  om
    return sum;
}

From source file:Main.java

public static BigInteger productOf(Collection<Integer> numbers) {
    BigInteger sum = BigInteger.ONE;
    for (Integer n : numbers) {
        sum = sum.multiply(BigInteger.valueOf(n));
    }//  ww w.j  a v  a2 s  .  c o m
    return sum;
}