# Integer.parseInt解读

int I = Integer.parseInt("123456");

    public static int parseInt(String s) throws NumberFormatException {
return parseInt(s,10);
}

    public static int parseInt(String s, int radix)
throws NumberFormatException
{
//输入为null，报错
if (s == null) {
throw new NumberFormatException("null");
}

//小于2进制数，报错
}

//大于36进制数，报错
}

int result = 0;

//是否为负数
boolean negative = false;
int i = 0, len = s.length();

//数值界限
int limit = -Integer.MAX_VALUE;
int multmin;
int digit;

if (len > 0) {
char firstChar = s.charAt(0);

//判断正负号
if (firstChar < '0') { // Possible leading "+" or "-"
if (firstChar == '-') {
negative = true;
limit = Integer.MIN_VALUE;
} else if (firstChar != '+')
throw NumberFormatException.forInputString(s);

if (len == 1) // Cannot have lone "+" or "-"
throw NumberFormatException.forInputString(s);

//转换起始位置加1
i++;
}
while (i < len) {
//把每一个字符，转换成对应的数字
if (digit < 0) {
throw NumberFormatException.forInputString(s);
}
if (result < multmin) {
throw NumberFormatException.forInputString(s);
}

//乘以进制数
//判断是非越界
if (result < limit + digit) {
throw NumberFormatException.forInputString(s);
}
//乘以进制数后，减去digit，以负数形式进行累加
result -= digit;
}
} else {
throw NumberFormatException.forInputString(s);
}
return negative ? result : -result;
}

digit		result		result*radix		result -=digit
1		0		0			   -1
2		-1		-10			   -12
3		-12		-120                        -123