Пример #1
0
        public static bool InHexFormat(string hexString)
        {
            bool result = true;

            for (int i = 0; i < hexString.get_Length(); i++)
            {
                char c = hexString.get_Chars(i);
                if (!HexEncoding.IsHexDigit(c))
                {
                    result = false;
                    break;
                }
            }
            return(result);
        }
Пример #2
0
        public static int GetByteCount(string hexString)
        {
            int num = 0;

            for (int i = 0; i < hexString.get_Length(); i++)
            {
                char c = hexString.get_Chars(i);
                if (HexEncoding.IsHexDigit(c))
                {
                    num++;
                }
            }
            if (num % 2 != 0)
            {
                num--;
            }
            return(num / 2);
        }
Пример #3
0
        public static byte[] GetBytes(string hexString, out int discarded)
        // hexString var is the string of text being read from the textbox in the app
        // discarded is an integer that is being referenced from the original void
        {
            discarded = 0;
            string text = "";

            for (int i = 0; i < hexString.get_Length(); i++) // Set i = 0 // Stop if i is greater than string length
            {
                char c = hexString.get_Chars(i);             // c var is declared as char and set equal to each char in the text string
                if (HexEncoding.IsHexDigit(c))               // If the char in the text string is a Hex digit...
                {
                    text += c;                               // text = text + c
                }
                else
                {
                    discarded++;                     // If it is not a hex digit, then increment discarded integer by 1?
                }
            }
            if (text.get_Length() % 2 != 0)                      // If the text string's length has a remainder greater other than zero
            {
                discarded++;                                     // Increment discarded integer by 1
                text = text.Substring(0, text.get_Length() - 1); // Update text string var = starting at substring index position 0, with a total length of the substring - 1
            }
            int num = text.get_Length() / 2;                     // var num integer = length of text string and divides by 2

            byte[] array = new byte[num];                        // Make a new array of bytes containing the amount of bytes specified by num variable
            int    num2  = 0;                                    // Make a new integer = 0

            for (int j = 0; j < array.Length; j++)               // Do until j exceeds length of the array
            {
                string hex = new string(new char[]               // Make a new string of chars named hex and get chars of bytes 0 and 1
                {
                    text.get_Chars(num2),
                    text.get_Chars(num2 + 1)
                });
                array[j] = HexEncoding.HexToByte(hex); // Turn hex into bytes for j array
                num2    += 2;                          // Advance position by 2?
            }
            return(array);                             // Returns a really f****d up array
        }