Java Utililty Methods Digit From

List of utility methods to do Digit From

Description

The list of methods to do Digit From are organized into topic(s).

Method

inttoDigit(char c)
to Digit
if (c >= '0' && c <= '9')
    return c - '0';
if (c >= 'a' && c <= 'f')
    return c - 'a' + 10;
if (c >= 'A' && c <= 'F')
    return c - 'A' + 10;
return -1;
inttoDigit(char ch)
Converts the character to a digit, throws an IllegalStateException if it isn't a valid digit.
if (('0' <= ch) && (ch <= '9')) {
    return ch - '0';
throw new IllegalStateException();
inttoDigit(char ch, int index)
to Digit
int digit = Character.digit(ch, 16);
if (digit == -1)
    throw new IllegalStateException("Illegal hexadecimal charcter " + ch + " at index " + index);
return digit;
inttoDigit(final boolean bit)
Converts a boolean into a digit.
return (bit) ? TRUE : FALSE;
inttoDigit(final char ch, final int index)
to Digit
final int digit = fastDigit(ch);
if (digit == -1) {
    throw new RuntimeException("Illegal hexadecimal charcter " + ch + " at index " + index);
return digit;
inttoDigit(final char ch, final int index)
Converts a hexadecimal character to an integer.
final int digit = Character.digit(ch, 16);
if (digit == -1) {
    throw new IllegalArgumentException("Illegal hexadecimal character " + ch + " at index " + index);
return digit;
chartoDigit(final int value)
to Digit
assert 0 <= value && value < RADIX;
return Character.forDigit(value, RADIX);
inttoDigit(int c)
to Digit
if (c > '9') {
    if (c > 'F') {
        if (c >= 'a' && c <= 'f') {
            return c - 'a' + 10;
    } else if (c >= 'A') {
        return c - 'A' + 10;
} else if (c >= '0') {
    return c - '0';
throw new IllegalArgumentException();
chartoDigit(int i)
Converts a digit to its char representation.
if (i >= 0 && i <= 9) {
    return (char) ('0' + i);
} else if (i >= 10 && i < 36) {
    return (char) ('A' + i - 10);
} else {
    throw new IllegalArgumentException("i must be at least 0 and no greater than 35. Invalid i: " + i);
chartoDigit(int n)
Returns the hex digit corresponding to a number n, from 0 to 15.
try {
    return hexDigits[n];
} catch (ArrayIndexOutOfBoundsException e) {
    throw new IllegalArgumentException(n + " is out of range for a hex digit");