38

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

2
  • Some of that doesn't make sense. There is no such thing as a 'BigInt in its decimal form'. The form of a BigInt is binary. Commented Nov 30, 2010 at 22:13
  • when i pass in a string to a bigint in hex form its converted to its decimal form! try it Commented Dec 2, 2010 at 14:00

1 Answer 1

78

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
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Excellent, all i was missing was the 16 to declare the input as hex!!,Thanks Jon

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.