本帖最后由 shan7719515 于 2012-07-31 11:33:57 编辑

解决方案 »

  1.   


                string str = "哈哈";
                byte[] buff = System.Text.Encoding.UTF8.GetBytes(str);
    根据你的实际需求,这里可能要有其他Encoding类型,例如System.Text.Encoding.Unicode.GetBytes(str);
      

  2.   

    可以的 
    System.Text.Encoding.GetEncoding("GBK")
      

  3.   

    这样不行的,也是经过转换的
    比如我转换得到16进制String str = “0x1B, 0x40, 0x1B, 0x57, 0x00, 0x00, 0x00, 0x00”
    变成byte类型的时候是这样的 byte[] b={0x1B, 0x40, 0x1B, 0x57, 0x00, 0x00, 0x00, 0x00}
    只改变类型不改变值
      

  4.   

    你想要这样?
    String str = "0x1B, 0x40, 0x1B, 0x57, 0x00, 0x00, 0x00, 0x00";
    String[] str1 = str.Replace(" ","").Split(',');
    byte[] b = new byte[str1.Length];
    for (int i = 0; i < str1.Length; i++)
    {
        b[i] = Convert.ToByte(Convert.ToInt32(str1[i], 16));
    }