Java Integer parseInt error

ぐ巨炮叔叔 提交于 2019-12-18 09:06:04

问题


I have following problem:

I want to convert some Binary Strings to an integer:

eargb = Integer.parseInt(al + re + gre + blu, 2);

but I get following exception. Why?

java.lang.NumberFormatException: For input string: "11111111111000101000100111111010"

回答1:


Your number (4,293,036,538) is too large to fit in a signed int (which has a range of -2,147,483,648 to 2,147,483,647).

Try using a long instead. This has a larger range.




回答2:


How about

long eargb = Long.parseLong(al + re + gre + blu, 2);



回答3:


Your binary number exceeded Integer size. Thats why your getting this exception




回答4:


It has been 7 months but the target answer has not been described. Also this question is leading in search engines. The above mentioned subjects are true. You should use as follow:

(int)Long.parseLong("11111111111000101000100111111010",2)

eargb =(int)Long.parseLong( al + re + gre + blu, 2);


来源:https://stackoverflow.com/questions/6896851/java-integer-parseint-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!