I am trying to parse a String like this:
f2cff0a43553b2e07b6ae3264bc085a
into a BigInt however when using the String constructor for BigInt I obviously get a Number format exception:
BigInteger bi = new BigInteger("f2cff0a43553b2e07b6ae3264bc085a");
Any ideas how I can do this?
Use the radix parameter:
BigInteger bi = new BigInteger("f2cff0a43553b2e07b6ae3264bc085a", 16);
Just use the constructor with the radix (using 16 as radix):
http://download.oracle.com/javase/6/docs/api/java/math/BigInteger.html#BigInteger%28java.lang.String,%20int%29
I think you just need to specify that the string is in hexadecimal. 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With