Java Utililty Methods Char to Nibble

List of utility methods to do Char to Nibble

Description

The list of methods to do Char to Nibble are organized into topic(s).

Method

intcharToNibble(char c)
char To Nibble
if ('0' <= c && c <= '9')
    return c - 48;
if ('a' <= c && c <= 'f')
    return (c - 97) + 10;
if ('A' <= c && c <= 'F')
    return (c - 65) + 10;
else
    throw new IllegalArgumentException(
...
intcharToNibble(char c)
convert a single char to corresponding nibble using a precalculated array.
if (c > 'f') {
    throw new IllegalArgumentException("Invalid hex character: " + c);
int nibble = correspondingNibble[c];
if (nibble < 0) {
    throw new IllegalArgumentException("Invalid hex character: " + c);
return nibble;
...
intcharToNibble(char c)
char To Nibble
if (c >= '0' && c <= '9') {
    return c - '0';
} else if (c >= 'a' && c <= 'f') {
    return 0xa + (c - 'a');
} else if (c >= 'A' && c <= 'F') {
    return 0xA + (c - 'A');
} else {
    throw new RuntimeException("Not a hex character: '" + c + "'");
...
intcharToNibble(char c)
char To Nibble
if (c > 'f') {
    throw new IllegalArgumentException("Invalid hex character: " + c);
int nibble = correspondingNibble[c];
if (nibble < 0) {
    throw new IllegalArgumentException("Invalid hex character: " + c);
return nibble;
...