Create a BigInt with a string encoded to base 16

I am trying to parse a string as follows:

f2cff0a43553b2e07b6ae3264bc085a

in BigInt, however, when using the String constructor for BigInt, I obviously get an exception in the Number format:

BigInteger bi = new BigInteger("f2cff0a43553b2e07b6ae3264bc085a"); 

Any ideas how I can do this?

+4
source share
3 answers

Use the radix parameter:

BigInteger bi = new BigInteger("f2cff0a43553b2e07b6ae3264bc085a", 16);

+6
source

I think you just need to indicate that the string is in hexadecimal format. Try

 BigInteger bi = new BigInteger("f2cff0a43553b2e07b6ae3264bc085a",16); 

http://www.java2s.com/Code/Java/Data-Type/ParsehexadecimalstringtocreateBigInteger.htm http://download.oracle.com/javase/1,5,0/docs/api/java/math/BigInteger.html #BigInteger (java.lang.String, int)

+1
source

Source: https://habr.com/ru/post/1380451/


All Articles