Example usage for java.math BigInteger toString

List of usage examples for java.math BigInteger toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the decimal String representation of this BigInteger.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    BigInteger bi = new BigInteger("1023");
    String s = bi.toString();
}

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 source file:Main.java

public static void main(String[] args) {

    BigInteger bi1 = new BigInteger("1234");
    BigInteger bi2 = new BigInteger("-1234");

    System.out.println(bi1.toString());
    System.out.println(bi2.toString());
}

From source file:Main.java

static BigInteger reverseNumber(BigInteger num) {
    String digits = num.toString();
    int numDigits = digits.length();
    char[] sb = new char[numDigits];
    for (int i = 0; i < digits.length(); i++) {
        sb[i] = digits.charAt(numDigits - i - 1);
    }//  w  w w. jav  a 2s .  com
    // Debug.println("rev",
    //    "reverseNumber(" + digits + ") -> " + "\"" + sb + "\"");
    return new BigInteger(new String(sb));
}

From source file:Main.java

/**
 * Transforms a byte array to a signed/*  w w w.java 2s  . c om*/
 * number String
 * @param in byte array
 * @return signed num String
 */
public static String bytesToSignedNumString(byte[] in) {
    BigInteger num = new BigInteger(in);
    return num.toString();
}

From source file:Main.java

/**
 * Transforms a byte array to a/*from w w  w.  ja v a 2 s  .  co m*/
 * positive number string
 * @param in byte array
 * @return positive number string
 */
public static String bytesToPositiveNumString(byte[] in) {
    BigInteger num = new BigInteger(1, in);
    return num.toString();
}

From source file:Main.java

/** Check if a number is palindromic. */
public static boolean isPalindrome(BigInteger num) {
    String digits = num.toString();
    int numDigits = digits.length();
    if (numDigits >= MAX_DIGITS) {
        throw new IllegalStateException("too big");
    }/*from  w  w  w  .j  a v  a2  s.co  m*/
    // Consider any single digit to be as palindromic as can be
    if (numDigits == 1)
        return true;
    for (int i = 0; i < numDigits / 2; i++) {
        // System.out.println(
        //    digits.charAt(i) + " ? " + digits.charAt(numDigits - i - 1));
        if (digits.charAt(i) != digits.charAt(numDigits - i - 1))
            return false;
    }
    return true;
}

From source file:org.cryptomath.util.NumberUtil.java

public static String spillFloats(BigInteger value, final int pTimes) {
    return NumberUtil.spillFloats(value.toString(), pTimes);
}

From source file:cn.ctyun.amazonaws.util.StringUtils.java

public static String fromBigInteger(BigInteger value) {
    return value.toString();
}

From source file:Main.java

public static String getValueShortString(BigInteger number) {
    BigInteger result = number;
    int pow = 0;/* ww w  . j a va2  s . co m*/
    while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) {
        result = result.divide(_1000_);
        pow += 3;
    }
    return result.toString() + "\u00b7(" + "10^" + pow + ")";
}