使用编码为基数 16 的字符串创建 BigInt
我正在尝试将这样的字符串解析:
f2cff0a43553b2e07b6ae3264bc085a
到 BigInt 中,但是当使用 BigInt 的字符串构造函数时,我显然得到了数字格式异常:
BigInteger bi = new BigInteger("f2cff0a43553b2e07b6ae3264bc085a");
有什么想法可以做到这一点吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用基数参数:
BigInteger bi = new BigInteger("f2cff0a43553b2e07b6ae3264bc085a", 16);
Use the radix parameter:
BigInteger bi = new BigInteger("f2cff0a43553b2e07b6ae3264bc085a", 16);
只需使用带基数的构造函数(使用 16 作为基数):
http://download.oracle.com/javase/6/docs/api/java/math/BigInteger.html#BigInteger%28java.lang.String,%20int%29
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
我认为你只需要指定该字符串是十六进制的。尝试
http://www.java2s.com/Code/Java/Data-输入/解析十六进制字符串以创建BigInteger.htm
http://download.oracle.com/javase/1,5,0/docs/api/java/math/BigInteger.html#BigInteger(java.lang.String, int)
I think you just need to specify that the string is in hexadecimal. Try
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)