有string="91013193",把它转化成对应的byte[]={0x91,0x01,0x31,0x93}

解决方案 »

  1.   


                string str = "91013193";
                byte[] result = new byte[str.Length / 2];
                for (int i = 0; i < str.Length; i += 2)
                {
                    result[i / 2] = Convert.ToByte(str.Substring(i, 2), 16);
                }
      

  2.   

    string str=BitConverter.ToString(new byte[] { 0x12, 0x9F }).Replace("-", string.Empty);
      

  3.   

       string str = "91013193";
                byte[] result = new byte[str.Length / 2];
                for (int i = 0; i < str.Length; i += 2)
                {
                    result[i / 2] = Convert.ToByte(str.Substring(i, 2), 16);
                }
      

  4.   

    一、
     string str = "91013193";
     byte[] result = new byte[str.Length / 2];
     for (int i = 0; i < str.Length; i += 2)
     {
         result[i / 2] = Convert.ToByte(str.Substring(i, 2), 16);
     }二、
    codestring str=BitConverter.ToString(new byte[] { 0x12, 0x9F }).Replace("-", string.Empty);