Java Utililty Methods BigInteger Create

List of utility methods to do BigInteger Create

Description

The list of methods to do BigInteger Create are organized into topic(s).

Method

BitSetCreate(BigInteger value)
Create a bitset from a positive BigInteger.
if (value.compareTo(BigInteger.ZERO) < 0)
    throw new IllegalArgumentException("value must be greater than zero (" + value + ")");
int numbits = value.bitLength() + 1;
BitSet newBS = new BitSet(numbits);
for (int index = 0; index < numbits; index += 1) {
    if (value.testBit(index)) {
        newBS.set(index);
return newBS;
BigIntegercreateBigInteger(final String str)
create Big Integer
if (str == null) {
    return null;
int pos = 0; 
int radix = 10;
boolean negate = false; 
if (str.startsWith("-")) {
    negate = true;
...
BigIntegercreateBigInteger(final String str)

Convert a String to a BigInteger; since 3.2 it handles hex (0x or #) and octal (0) notations.

Returns null if the string is null.

if (str == null) {
    return null;
int pos = 0; 
int radix = 10;
boolean negate = false; 
if (str.startsWith("-")) {
    negate = true;
...
BigIntegercreateBigInteger(final String value)
This method creates a new big-integer.
return new BigInteger(value);
BigIntegercreateBigInteger(String str)
create Big Integer
if (str == null) {
    return null;
return new BigInteger(str);
BigIntegercreateBigInteger(String str)

Convert a String to a BigInteger.

Returns null if the string is null.

if (str == null) {
    return null;
return new BigInteger(str);
BigIntegerhexToBigInteger(String hex)
hex To Big Integer
return new BigInteger(hex, 16);
BigIntegerhexToBigInteger(String hex)
Convert hex to BigInteger.
if (hex == null) {
    return null;
if (hex.startsWith("0x")) {
    hex = hex.substring(2);
while (hex.length() > 1 && hex.charAt(0) == '0') {
    hex = hex.substring(1);
...
BigIntegertoBigInteger(byte[] bytes)
to Big Integer
if (bytes[0] == -128) {
    return new BigInteger(bytes);
} else {
    return new BigInteger(1, bytes);
BigIntegertoBigInteger(final byte[] array, final int offset, final int length)
to Big Integer
BigInteger result = new BigInteger(1, new byte[] {});
for (int i = (offset + length - 1); i >= offset; i--) {
    result = result.shiftLeft(8);
    result = result.or(BigInteger.valueOf(array[i] & 0xFF));
return result;