使用编码为基数 16 的字符串创建 BigInt

发布于 2024-12-14 08:01:26 字数 237 浏览 3 评论 0原文

我正在尝试将这样的字符串解析:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜血缘 2024-12-21 08:01:26

使用基数参数:

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

Use the radix parameter:

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

黑色毁心梦 2024-12-21 08:01:26

我认为你只需要指定该字符串是十六进制的。尝试

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

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

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文