| Code with Finding: |
class Hex {
/**
* Interprets the character <code>c</code> as hexadecimal digit.
*
* @param c a character from '0', '1', '2', '3', '4', '5', '6', '7', '8',
* '9', 'A', 'B', 'C', 'D', 'E', 'F'.
*
* @return the decimal-hexadecimal digit interpretation of
* <code>c</code>.
*/
static int hexDigitToInt(char c)
throws NumberFormatException {
switch (c) {
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
case 'a': case 'A': return 10;
case 'b': case 'B': return 11;
case 'c': case 'C': return 12;
case 'd': case 'D': return 13;
case 'e': case 'E': return 14;
case 'f': case 'F': return 15;
default: throw new NumberFormatException();
}
}
}
|