把字符串加工成16进制的字节数组并返回

  //把字符串加工成16进制的字节数组并返回(必须要保证数据格式的正确性<字符个数为偶数>)
        public byte[] GetHEXByteArray(string sendvalue)
        {
            
int sendLength = sendvalue.Length / 2;
            
byte[] StrBuffer = new byte[sendLength];
            
string hexstring = "";
            
int k = 0;
            
for (int i = 0; i < sendvalue.Length; )
            {
                hexstring 
= sendvalue.Substring(i, 2);
                
int j;
                j 
= int.Parse(hexstring, System.Globalization.NumberStyles.HexNumber);
                StrBuffer[k] 
= (byte)j;
                i 
+= 2;
                k
++;
            }
            
return StrBuffer;
        }

////////////////////////////////
////////Sixi. Let it be.../////
//////////////////////////////

原文地址:https://www.cnblogs.com/sixiweb/p/1430671.html