【发布时间】:2016-07-21 15:22:25
【问题描述】:
我正在开发一个程序,我正在尝试使用以下代码将二进制字符串转换为整数:
int x = Integer.parseInt(arrayList.get(count), 2);
//arrayList is a collection of 30 character binary strings
//count is an incrementing integer used to choose which string to use while inside of a while loop
我已经使用诸如“001010”之类的字符串测试了该程序,但是使用诸如“100000110000010100001111010110”之类的较大字符串可以编译,但是终端输出给我一个错误:
"@ java.lang.NumberFormatException.forInputString(NumberFormatException.java:(line number))
我该如何解决这个问题?
【问题讨论】:
-
我会尝试使用
long或BigInteger -
编辑:试过'long decimalValue = Long.parseLong(arrayList.get(count), 2); '返回同样的错误
-
比
9二进制数字长多少? -
在我的例子中,我的字符串是 30 位二进制