private static readonly Regex _asciiPattern = new Regex("^[\x20-\x7F]{32}$", RegexOptions.Compiled); // Pattern for string in ASCII code (alphanumeric symbols) private void ParseCID(string cid) { if (String.IsNullOrWhiteSpace(cid) || !_asciiPattern.IsMatch(cid)) return; var bytes = SoapHexBinary.Parse(cid).Value; ManufacturerID = bytes[0]; // Bytes 0 OemApplicationID = Encoding.ASCII.GetString(bytes.Skip(1).Take(2).ToArray()); // Bytes 1-2 ProductName = Encoding.ASCII.GetString(bytes.Skip(3).Take(5).ToArray()); // Bytes 3-7 var productRevisionBits = new BitArray(new[] { bytes[8] }).Cast<bool>().Reverse().ToArray(); // Bytes 8 var major = ConvertFromBitsToInt(productRevisionBits.Take(4).Reverse()); var minor = ConvertFromBitsToInt(productRevisionBits.Skip(4).Take(4).Reverse()); ProductRevision = String.Format("{0}.{1}", major, minor); ProductSerialNumber = BitConverter.ToUInt32(bytes, 9); // Bytes 9-12 var manufacturingDateBits = bytes.Skip(13).Take(2) // Bytes 13-14 .SelectMany(x => new BitArray(new[] { x }).Cast<bool>().Reverse()) .Skip(4) // Skip reserved field. .ToArray(); var year = ConvertFromBitsToInt(manufacturingDateBits.Take(8).Reverse()); var month = ConvertFromBitsToInt(manufacturingDateBits.Skip(8).Take(4).Reverse()); if ((year <= 1000) && (month <= 12)) { ManufacturingDate = new DateTime(year + 2000, month, 1); } }