Java BigInteger to bigIntegerToString(final BigInteger value)

Here you can find the source of bigIntegerToString(final BigInteger value)

Description

Customized string representation of BigInteger.

License

Open Source License

Parameter

Parameter Description
value value to be converted

Return

string representatioin of value

Declaration

public static String bigIntegerToString(final BigInteger value) 

Method Source Code


//package com.java2s;
/* Util.java//from  www  . j  a  v  a  2 s  . com
 *
 * Copyright (C) 2015, Tom? Pecina <tomas@pecina.cz>
 *
 * This file is part of cz.pecina.bin, a suite of binary-file
 * processing applications.
 *
 * This application is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This application is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.         
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.math.BigInteger;

public class Main {
    /**
     * Customized string representation of BigInteger.
     *
     * @param  value value to be converted
     * @return       string representatioin of <code>value</code>
     */
    public static String bigIntegerToString(final BigInteger value) {
        if (value == null) {
            return "null";
        } else if (value.signum() < 0) {
            return "-0x" + value.negate().toString(16);
        } else {
            return "0x" + value.toString(16);
        }
    }

    @Override
    public String toString() {
        return "Util";
    }
}

Related

  1. bigIntegerToBytes(final BigInteger bigInteger)
  2. bigIntegerToDigits(BigInteger n)
  3. BigIntegerToEightBytes(BigInteger value)
  4. bigIntegerToHex(final BigInteger bigInteger)
  5. bigIntegerToList(BigInteger number)
  6. bigIntegerToUnsignedByteArray(BigInteger a, int len)
  7. bigIntToArray(BigInteger data)
  8. bigIntToHash(BigInteger keyValue)
  9. bigIntToHex(BigInteger big)