public int getHex(string src) { int hex, hex2; string [] buf = new string [2]; buf[0] = src.Substring(0,1); buf[1] = src.Substring(1,1); switch (buf[0]) { case "1": hex = 0x10; break; case "2": hex = 0x20; break; case "3": hex = 0x30; break; case "4": hex = 0x40; break; case "5": hex = 0x50; break; case "6": hex = 0x60; break; case "7": hex = 0x70; break; case "8": hex = 0x80; break; case "9": hex = 0x90; break; case "0": hex = 0x00; break; case "a": case "A": hex = 0xa0; break; case "b": case "B": hex = 0xb0; break; case "c": case "C": hex = 0xc0; break; case "d": case "D": hex = 0xd0; break; case "e": case "E": hex = 0xe0; break; case "f": case "F": hex = 0xf0; break; default: return 0; } switch (buf[1]) { case "1": hex2 = 0x01; break; case "2": hex2 = 0x02; break; case "3": hex2 = 0x03; break; case "4": hex2 = 0x04; break; case "5": hex2 = 0x05; break; case "6": hex2 = 0x06; break; case "7": hex2 = 0x07; break; case "8": hex2 = 0x08; break; case "9": hex2 = 0x09; break; case "0": hex2 = 0x00; break; case "a": case "A": hex2 = 0x0a; break; case "b": case "B": hex2 = 0x0b; break; case "c": case "C": hex2 = 0x0c; break; case "d": case "D": hex2 = 0x0d; break; case "e": case "E": hex2 = 0x0e; break; case "f": case "F": hex2 = 0x0f; break; default: return 0; } return hex + hex2; }