Example usage for java.math BigInteger BigInteger

List of usage examples for java.math BigInteger BigInteger

Introduction

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

Prototype

private BigInteger(long val) 

Source Link

Document

Constructs a BigInteger with the specified value, which may not be zero.

Usage

From source file:Main.java

public static void main(String[] args) {

    // assign values to bi1, bi2
    BigInteger bi1 = new BigInteger("6");
    BigInteger bi2 = new BigInteger("-6");

    // perform not operation on bi1 and bi2
    BigInteger bi3 = bi1.not();//  w  w  w.  ja  va2 s  .c o  m
    BigInteger bi4 = bi2.not();

    System.out.println(bi3);
    System.out.println(bi4);
}

From source file:Main.java

public static void main(String[] args) {

    // assign values to bi1, bi2
    BigInteger bi1 = new BigInteger("123");
    BigInteger bi2 = new BigInteger("987654321");

    // assign the integer values of bi1, bi2 to i1, i2
    Integer i1 = bi1.intValue();/*from w w  w.  ja  v  a2s .  c  o  m*/
    Integer i2 = bi2.intValue();

    System.out.println(i1);
    System.out.println(i2);
}

From source file:Main.java

public static void main(String[] args) {
    BigInteger bigInteger = new BigInteger("2000000000000");// uper limit
    BigInteger min = new BigInteger("1000000000");// lower limit
    BigInteger bigInteger1 = bigInteger.subtract(min);
    Random rnd = new Random();
    int maxNumBitLength = bigInteger.bitLength();

    BigInteger aRandomBigInt;/*from w ww.  j a v  a  2 s.  co m*/

    aRandomBigInt = new BigInteger(maxNumBitLength, rnd);
    if (aRandomBigInt.compareTo(min) < 0)
        aRandomBigInt = aRandomBigInt.add(min);
    if (aRandomBigInt.compareTo(bigInteger) >= 0)
        aRandomBigInt = aRandomBigInt.mod(bigInteger1).add(min);

    System.out.println(aRandomBigInt);
}

From source file:Main.java

public static void main(String[] args) {

    // assign values to bi1, bi2
    BigInteger bi1 = new BigInteger("123");
    BigInteger bi2 = new BigInteger("-123");

    // assign float values of bi1, bi2 to f1, f2
    Float f1 = bi1.floatValue();//from   ww  w .  jav  a 2  s.c om
    Float f2 = bi2.floatValue();

    // print f1, f2 values
    System.out.println(f1);
    System.out.println(f2);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // Create via a string
    BigInteger bi1 = new BigInteger("1234567890123456890");

    // Create via a long
    BigInteger bi2 = BigInteger.valueOf(123L);

    bi1 = bi1.add(bi2);//www.j  a v  a 2 s  .  c om

}

From source file:Main.java

public static void main(String[] args) {

    // assign values to bi1, bi2
    BigInteger bi1 = new BigInteger("7");
    BigInteger bi2 = new BigInteger("9");

    // perform isProbablePrime on bi1, bi2
    Boolean b1 = bi1.isProbablePrime(1);
    Boolean b2 = bi2.isProbablePrime(1);
    Boolean b3 = bi2.isProbablePrime(-1);

    System.out.println(b1);/*  ww  w .  j ava 2  s  .c  o m*/
    System.out.println(b2);
    System.out.println(b3);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // Create via a string
    BigInteger bi1 = new BigInteger("1234567890123456890");

    // Create via a long
    BigInteger bi2 = BigInteger.valueOf(123L);

    bi1 = bi1.add(bi2);/*  www.j  av a 2 s .  com*/
    bi1 = bi1.multiply(bi2);
    bi1 = bi1.subtract(bi2);
    bi1 = bi1.divide(bi2);
    bi1 = bi1.negate();
    int exponent = 2;
    bi1 = bi1.pow(exponent);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    byte[] bytes = new byte[] { 0x1, 0x00, 0x00 };
    BigInteger bi = new BigInteger(bytes);
    bytes = bi.toByteArray();//from   ww  w  .j a  v a2s .  c o  m
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    byte[] bytes = new byte[] { 0x1, 0x00, 0x00 };
    BigInteger bi = new BigInteger(bytes);
    bi = bi.or(bi);// w  ww .  ja  v  a2  s  .co  m
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    byte[] bytes = new byte[] { 0x1, 0x00, 0x00 };
    BigInteger bi = new BigInteger(bytes);
    bi = bi.and(bi);/*from w  w w. j  ava  2  s. co m*/
}