Beispiel #1
0
        public static byte[] GetBytes(string hexString)
        {
            int           num           = 0;
            StringBuilder stringBuilder = new StringBuilder();

            for (int index = 0; index < hexString.Length; ++index)
            {
                char c = hexString[index];
                if (HexEncoding.IsHexDigit(c))
                {
                    stringBuilder.Append(c);
                }
                else
                {
                    ++num;
                }
            }
            string str = stringBuilder.ToString();

            byte[] numArray = new byte[str.Length / 2];
            int    index1   = 0;

            for (int index2 = 0; index2 < numArray.Length; ++index2)
            {
                string hex = new string(new char[2]
                {
                    str[index1],
                    str[index1 + 1]
                });
                numArray[index2] = HexEncoding.HexToByte(hex);
                index1          += 2;
            }
            return(numArray);
        }
Beispiel #2
0
        public static bool InHexFormat(string hexString)
        {
            bool flag = true;

            foreach (char c in hexString)
            {
                if (!HexEncoding.IsHexDigit(c))
                {
                    flag = false;
                    break;
                }
            }
            return(flag);
        }
Beispiel #3
0
        public static int GetByteCount(string hexString)
        {
            int num = 0;

            for (int index = 0; index < hexString.Length; ++index)
            {
                if (HexEncoding.IsHexDigit(hexString[index]))
                {
                    ++num;
                }
            }
            if (num % 2 != 0)
            {
                --num;
            }
            return(num / 2);
        }