问题
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