user524156
user524156

Reputation: 725

Java convert a HEX String to a BigInt

Hi am trying to convert a hex string such as String hexStr = "1b0ee1e3"; to a bigInt, ideally i'd like to convert hexStr to a bigint in its decimal form,

I can convert a string to a bigInt w/o issues but when the string contains hex values i run into problems

Upvotes: 38

Views: 43064

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500635

Have you tried:

BigInteger bigInt = new BigInteger(hexString, 16);

For example:

import java.math.*;

public class Test {
    public static void main(String[] args) {
        String hexStr = "1b0ee1e3";
        BigInteger bigInt = new BigInteger(hexStr, 16);
        System.out.println(bigInt); // Prints 453960163
    }
}

Upvotes: 77

Related Questions