Java BigInteger to convert(BigInteger value, int base, boolean extra)

Here you can find the source of convert(BigInteger value, int base, boolean extra)

Description

Convert value to a string in the given base.

License

Open Source License

Parameter

Parameter Description
The value to convert.
base The base.
True if prefix or suffix needed, false if not.

Return

the string.

Declaration

public static String convert(BigInteger value, int base, boolean extra) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.math.BigInteger;

public class Main {
    /**//from   www .  java2 s  .co m
     * Convert value to a string in the given base.
     * 
     * @param The value to convert.
     * @param base The base.
     * @param True if prefix or suffix needed, false if not.
     * 
     * @return the string.
     */
    public static String convert(BigInteger value, int base, boolean extra) {

        if (base == 2) {
            if (extra)
                return value.toString(2) + "B";
            else
                return value.toString(2);
        } else if (base == 10) {
            return value.toString();
        } else if (base == 16) {
            if (extra)
                return "0x" + value.toString(16);
            else
                return value.toString(16);
        }
        return ""; // shouldn't happen
    }
}

Related

  1. BigIntToPaddedByteArray(BigInteger bi, int length)
  2. bigIntToSortableBytes(BigInteger bigInt, int bigIntSize, byte[] result, int offset)
  3. biToHex(BigInteger bi)
  4. byteConvert32Bytes(BigInteger n)
  5. concat(BigInteger left, BigInteger right)
  6. convertAllElementsToLong(P bigIntegers)
  7. convertBigIntegerIntoInetAddress(final BigInteger i)
  8. convertBigIntegerToNBytes( final BigInteger bigInteger, final int numBytes)
  9. convertPositive(BigInteger bi)