public static byte[] HexToByte(string input) {
int Valid = 0;
bool High = true;
int Buffer = 0;
int Index = 0;
foreach (char c in input) {
if (HexValue(c) >= 0) Valid++;
}
var Result = new byte[(Valid + 1) / 2];
foreach (char c in input) {
var h = HexValue(c);
if (h >= 0) {
if (High) {
Buffer = h;
}
else {
Result[Index++] = (byte)(h + (Buffer * 16));
}
High = !High;
}
}
return Result;
}