Java BigInteger Create hexToBigInteger(String hex)

Here you can find the source of hexToBigInteger(String hex)

Description

Convert hex to BigInteger.

License

Apache License

Parameter

Parameter Description
hex to convert

Return

biginteger from hex

Declaration

public static BigInteger hexToBigInteger(String hex) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.math.BigInteger;

public class Main {
    /**/*from www  . j  ava 2  s  .com*/
     * Convert hex to BigInteger.
     *
     * @param hex
     *            to convert
     * @return biginteger from hex
     */
    public static BigInteger hexToBigInteger(String hex) {
        if (hex == null) {
            return null;
        }

        if (hex.startsWith("0x")) {
            hex = hex.substring(2);
        }

        // remove starting zeros
        while (hex.length() > 1 && hex.charAt(0) == '0') {
            hex = hex.substring(1);
        }

        return new BigInteger(hex, 16);
    }
}

Related

  1. createBigInteger(final String str)
  2. createBigInteger(final String value)
  3. createBigInteger(String str)
  4. createBigInteger(String str)
  5. hexToBigInteger(String hex)
  6. toBigInteger(byte[] bytes)
  7. toBigInteger(final byte[] array, final int offset, final int length)
  8. toBigInteger(final byte[] buffer, final int offset, final int length)
  9. toBigInteger(final byte[] bytes)