Java整数解析错误
我有以下问题:
我想将一些二进制字符串转换为整数:
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"
推荐答案
您的数字 (4,293,036,538) 太大而无法放入带符号的 int(范围为 -2,147,483,648 到 2,147,483,647)中.
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).
尝试使用 long 来代替.这个范围更大.
Try using a long instead. This has a larger range.
相关文章