输入字符串中的 NumberFormatException
请帮我解决这个异常:-
String strBinary="100000000000000001000000000000000000000000000000000000000000000000000000";
System.out.println("length is " + strBinary.length());
long intParse=Long.parseLong(strBinary, 2);
System.out.println("int parsed is " + intParse);
String hexString=Long.toHexString(intParse);
System.out.println(hexString);
使用 Long.parseLong 解析时输出为 72 以及 NumberFormatException。 但直到昨天,这个输入也运行得非常好。 和长度有关系吗... 我实际上正在尝试将字符串转换为其等效的十六进制值。
请帮忙....
Please help me solve this exception:-
String strBinary="100000000000000001000000000000000000000000000000000000000000000000000000";
System.out.println("length is " + strBinary.length());
long intParse=Long.parseLong(strBinary, 2);
System.out.println("int parsed is " + intParse);
String hexString=Long.toHexString(intParse);
System.out.println(hexString);
Output is 72 along with NumberFormatException while parsing using Long.parseLong..
But till yesterday it was running absolutely fine for this input also..
does it have anything to do with the length...
I am actuallly trying to convert String into its equivalent Hex value.
Please help....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
long
可以保存 64 位数据。long
可以表示的最大值是 9223372036854775807(或 263-1)。您尝试解析的字符串比该字符串大得多。您可能可以使用
BigInteger
类,它可以处理任意大小的整数值(当然,有效地受内存限制)。A
long
can hold 64 bit of data. The biggest value along
can represent is 9223372036854775807 (or 263-1). The string you try to parse is a lot larger than that.You might be able to go somewhere by using the
BigInteger
class, which can handle arbitrary-sized integer values (effectively restricted by memory, of course).长对于您的目的来说很小。您可能想像这样使用 BigInteger 对象
Long is small for your purpose. You might want to use BigInteger object like this