public static string ToHex(byte[] value, int startIndex, int endIndex)
        {
            int length = endIndex - startIndex + 1;
            char[] chars = new char[length << 1];
            byte byteValue;
            int i;
            int p;
            for (int index = startIndex; index <= endIndex; index++)
            {
                byteValue = value[index];
                i = byteValue / 0x10;
                p = index * 2;
                if (i < 10)
                {
                    chars[p] = (char)(i + 0x30);
                }
                else
                {
                    chars[p] = (char)((i - 10) + 0x41);
                }                i = byteValue % 0x10;
                if (i < 10)
                {
                    chars[p + 1] = (char)(i + 0x30);
                }
                else
                {
                    chars[p + 1] = (char)((i - 10) + 0x41);
                }
            }            return new string(chars);
        }        public static byte[] ToString(string value)
        {
            int charValue;
            int v1;
            int v2;
            int length = value.Length / 2;
            byte[] bytes = new byte[length];
            int p = 0;
            for (int index = 0; index < length; index ++)
            {
                p = index * 2;
                charValue = (int)value[p];
                if (charValue < 58)
                {
                    v1 = (charValue - 0x30) * 0x10;
                }
                else
                {
                    v1 = (charValue - 0x41 + 10) * 0x10;
                }                charValue = (int)value[p + 1];
                if (charValue < 58)
                {
                    v2 = charValue - 0x30;
                }
                else
                {
                    v2 = charValue - 0x41 + 10;
                }                bytes[index] = (byte)(v1 + v2);
            }            return bytes;
        }        public static string stringToHex(string value)
        {
            byte[] bytes = Encoding.UTF8.GetBytes(value);
            string a = ToHex(bytes,0,bytes.Length-1);
            return a;
        }        public static string HexTostring(string s)
        {
            byte[] bytes = ToString(s);
            return Encoding.UTF8.GetString(bytes);
        }