Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the Integer.parseInt () source code

Shulou Source: shulou.com Published: 2022-06-02 04:24:19 09月17日 Update

This article will explain in detail what is the Integer.parseInt () source code, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Character.digit (char ch, int radix) converts radix ch into decimal numbers.

Character.digit (int codePoint, int radix) converts the char corresponding to the askll code in radix into a decimal number.

Example: String slots 2147483648

The initial value of result is 0

Limit=-Integer.MAX_VALUE, i.e.-2147483647

In the last result and limit comparison, 21474836471 was excluded.

Comparing the current bits of result*10 and limit+, excluding the out of bounds of 2147483648 (- 2147483640 Character.MAX_RADIX) {throw new NumberFormatException ("radix" + radix + "greater than Character.MAX_RADIX");} 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); iTunes + } multmin = limit / radix; while (I < len) {/ / Accumulating negatively avoids surprises near MAX_VALUE digit = Character.digit (s.charAt (iTunes +), radix); if (digit < 0) {throw NumberFormatException.forInputString (s) } / / prevent the length from exceeding the limit if (result < multmin) {throw NumberFormatException.forInputString (s);} result * = radix / / prevent if (result < limit + digit) {throw NumberFormatException.forInputString (s);} result-= digit;}} else {throw NumberFormatException.forInputString (s);} return negative? Result:-result;} on what is Integer.parseInt () source code to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Source code content decimal situation article more knowledge article binary decimal good size quality length reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Docker macOS Apple Xiaomi