int (@NotNull CharSequence value, int start, boolean isNegative, int radix) { final int end = value.length(); int result = 0; // Accumulates negatively (avoid MIN_VALUE overflow). int i = start; for (; i < end; i++) { char c = value.charAt(i); int digit = (c <= '9') ? c - '0' : ((c <= 'Z') && (c >= 'A')) ? c - 'A' + 10 : ((c <= 'z') && (c >= 'a')) ? c - 'a' + 10 : -1; if ((digit >= 0) && (digit < radix)) { int newResult = result * radix - digit; if (newResult > result) { throw new NumberFormatException("Overflow parsing " + value.subSequence(start, end)); } result = newResult; } else { break; } } // Requires one valid digit character and checks for opposite overflow. if ((result == 0) && ((end == 0) || (value.charAt(i - 1) != '0'))) { throw new NumberFormatException("Invalid integer representation for " + value.subSequence(start, end)); } if ((result == Integer.MIN_VALUE) && !isNegative) { throw new NumberFormatException("Overflow parsing " + value.subSequence(start, end)); } return isNegative ? result : -result; }