6

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?

SnowyTracks
  • 1,965
  • 15
  • 21

3 Answers3

9

Use the radix parameter:

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

Jonathon Faust
  • 12,396
  • 4
  • 50
  • 63
3

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

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
1

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)

jmcdale
  • 4,463
  • 2
  • 16
  • 20