public static int hex2int( char hex ) 
	throws NumberFormatException {

	// '0' to '9' in ASCII: 48 to 57 (dec)
	// 'A' to 'F' in ASCII: 65 to 70 (dec)
	// 'a' to 'f' in ASCII: 97 to 102 (dec)
	
	if( hex >= 48 && hex <= 57 ) {

	    // '0' to '9'
	    return (hex-48);

	} else if( hex >= 97 && hex <= 102 ) {

	    // 'a' to 'f'
	    return (10 + hex-97);

	} else if( hex >= 65 && hex <= 70 ) {

	    // 'A' to 'F'
	    return (10 + hex-65);

	} else {

	    throw new NumberFormatException( "Cannot convert char '"+hex+"' to hex-nibble (not a hexadecimal character)." );

	}

    }