How can I convert a large string to integer in java?

biginteger, hex, java, parseint, string

Solution

Have you tried the `BigInteger` constructor taking a string and a radix?

BigInteger value = new BigInteger(hex, 16);

Sample code:

import java.math.BigInteger;

public class Test {

    public static void main(String[] args) {
        String hex = "3132333435363738396162636465666768696a6b6c6d6e6f70";
        BigInteger number = new BigInteger(hex , 16);
        System.out.println(number); // As decimal...
    }
}

Output:

308808885829455478403317837970537433512288994552567292653424

Problem

Given the following string: ``` 3132333435363738396162636465666768696a6b6c6d6e6f70 ``` I converted the string to hex and now i want to file write it as hex not a string. I tried converting it to int but `Integer.parseInt` converts up to 4 only and if go beyond that it would give error already.

Original source