public static int CharToHex(char c) { if (c >= '0' && c <= '9') return (int)c - 48; if (c >= 'A' && c <= 'F') return 10 + (int)c - 65; else if (c >= 'a' && c <= 'f') return 10 + (int)c - 97; else return 0; }