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[] argv) throws Exception {

    byte[] bytes = new byte[] { (byte) 0x12, (byte) 0x0F, (byte) 0xF0 };

    BigInteger bi = new BigInteger(bytes);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    byte[] bytes = new byte[] { (byte) 0x12, (byte) 0x0F, (byte) 0xF0 };

    BigInteger bi = new BigInteger(bytes);

    // Format to decimal
    String s = bi.toString();//from   w  ww .  j ava  2  s  .c o  m
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    byte[] bytes = new byte[] { (byte) 0x12, (byte) 0x0F, (byte) 0xF0 };

    BigInteger bi = new BigInteger(bytes);

    // Format to octal
    String s = bi.toString(8);/* ww  w  . j a  va  2s .c o  m*/
    System.out.println(s);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    byte[] bytes = new byte[] { (byte) 0x12, (byte) 0x0F, (byte) 0xF0 };

    BigInteger bi = new BigInteger(bytes);

    // Format to hexadecimal
    String s = bi.toString(16);/*from w w w.  j a  va  2s  . c  om*/
    if (s.length() % 2 != 0) {
        s = "0" + s;
    }
}

From source file:Main.java

public static void main(String[] args) {
    System.out.printf("%o %n", 1234);
    System.out.printf("%o %n", -1234);
    System.out.printf("%o %n", new BigInteger("1234"));
    System.out.printf("%o %n", new BigInteger("-1234"));

    System.out.printf("%x %n", 1234);
    System.out.printf("%x %n", -1234);
    System.out.printf("%x %n", new BigInteger("1234"));
    System.out.printf("%x %n", new BigInteger("-1234"));

    System.out.printf("%#o %n", 1234);
    System.out.printf("%#x %n", 1234);
    System.out.printf("%#o %n", new BigInteger("1234"));
    System.out.printf("%#x %n", new BigInteger("1234"));

}

From source file:Main.java

public static void main(String[] args) {
    MathContext mc = new MathContext(3);
    BigDecimal bg1 = new BigDecimal(new BigInteger("40"), 2, mc);

}

From source file:Main.java

public static void main(String[] args) {
    MathContext mc = new MathContext(3);
    BigDecimal bg1 = new BigDecimal(new BigInteger("40"), mc);

}

From source file:Main.java

public static void main(String[] args) {

    // create and assign value to byte array b3
    byte b3[] = { 0x1, 0x00, 0x00 };

    BigInteger bi1 = new BigInteger("10");
    BigInteger bi2 = new BigInteger(b3); // using byte[] constructor of
                                         // BigInteger

    // assign byte array representation of bi1, bi2 to b1, b2
    byte[] b1 = bi1.toByteArray();
    byte[] b2 = bi2.toByteArray();

    for (int i = 0; i < b1.length; i++) {
        System.out.format("0x%02X\n", b1[i]);
    }// w  w  w . j a v a2 s  .c  om
    // print byte array b2 using for loop
    for (int j = 0; j < b2.length; j++) {
        System.out.format("0x%02X ", b2[j]);
    }
}

From source file:Main.java

public static void main(String... a) {
    int n = 16;//  ww w.jav a  2s  .c  o  m

    Random r = new Random();
    byte[] b = new byte[n];
    r.nextBytes(b);
    BigInteger i = new BigInteger(b);

    System.out.println(i);
}

From source file:Main.java

public static void main(String[] args) {
    int i = 0;// ww w  .  j  av a2s  .co m
    while (true) {
        if (i > 1000) {
            break;
        }
        if (i > 1) {
            if (new BigInteger(i + "").isProbablePrime(i / 2)) {
                System.out.println(i);
            }
        }
        i++;
    }
}