Convenience method to determine the value of the specified character c in the supplied radix. The value of radix must be between MIN_RADIX and MAX_RADIX. @param c the character to determine the value of. @param radix the radix. @return the value of c in
(char c, int radix)
| 2756 | * between {@link #MIN_RADIX} and {@link #MAX_RADIX}; -1 otherwise. |
| 2757 | */ |
| 2758 | public static int digit(char c, int radix) { |
| 2759 | if (radix >= MIN_RADIX && radix <= MAX_RADIX) { |
| 2760 | if (c < 128) { |
| 2761 | // Optimized for ASCII |
| 2762 | int result = -1; |
| 2763 | if ('0' <= c && c <= '9') { |
| 2764 | result = c - '0'; |
| 2765 | } else if ('a' <= c && c <= 'z') { |
| 2766 | result = c - ('a' - 10); |
| 2767 | } else if ('A' <= c && c <= 'Z') { |
| 2768 | result = c - ('A' - 10); |
| 2769 | } |
| 2770 | return result < radix ? result : -1; |
| 2771 | } |
| 2772 | // int result = BinarySearch.binarySearchRange(digitKeys, c); |
| 2773 | // if (result >= 0 && c <= digitValues[result * 2]) { |
| 2774 | // int value = (char) (c - digitValues[result * 2 + 1]); |
| 2775 | // if (value >= radix) { |
| 2776 | // return -1; |
| 2777 | // } |
| 2778 | // return value; |
| 2779 | // } |
| 2780 | } |
| 2781 | return -1; |
| 2782 | } |
| 2783 | |
| 2784 | /** |
| 2785 | * Convenience method to determine the value of the character |