37

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

user524156
  • 715
  • 2
  • 10
  • 16

1 Answers1

75

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
    }
}
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194