在Java中解析大十六进制数 [英] Parsing big hexadecimal numbers in Java
本文介绍了在Java中解析大十六进制数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试解析 int
a String
这是我的代码中的十六进制数字(FF00FF00,for例子)使用 Integer.parseInt(String string,int radix)
,但总是得到 NumberFormatException
。如果我解析没有最后两个数字(FF00FF)的数字,它运行良好。
I'm trying to parse into int
a String
which is hexadecimal number in my code (FF00FF00, for example) using Integer.parseInt(String string, int radix)
, but always get NumberFormatException
. If I parse the number without last two numbers (FF00FF) it works well.
是否有任何方法可以解析Java中的大数字?
Is there any method to parse such big numbers in Java?
推荐答案
如果整数太小,请使用 长
:
If Integer is too small, use Long
:
Long.parseLong(string, 16)
如果Long仍然太小,请使用 BigInteger
:
If Long is still too small, use BigInteger
:
new BigInteger(string, 16)
这篇关于在Java中解析大十六进制数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文