我想将60 00 03 00 05 00 07 08 00 20 38 00 00 00 00 00 1e 35 00 00 二进制
以2进制的形式存入byte里面去如byte[] data =new byte[1024];
现在如何将60 00 03 00 05 00 07 08 00 20 38 00 00 00 00 00 1e 35 00 00
存进入?存进去表示也是60 00 03 00 05 00 07 08 00 20 38 00 00 00 00 00 1e 35 00 00

解决方案 »

  1.   

    借花献佛,http://blog.csdn.net/feishanm/archive/2008/10/20/3112716.aspx
            private static byte[] strToToHexByte(string hexString)
            {
                hexString = hexString.Replace(" ", "");
                if ((hexString.Length % 2) != 0)
                    hexString += " ";
                byte[] returnBytes = new byte[hexString.Length / 2];
                for (int i = 0; i < returnBytes.Length; i++)
                    returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
                return returnBytes;
            }
      

  2.   

    class HexCon {
    //converter hex string to byte and byte to hex string
    public static string ByteToString(byte[] InBytes) {
    string StringOut="";
    foreach (byte InByte in InBytes) {
    StringOut=StringOut + String.Format("{0:X2} ",InByte);
    }
    return StringOut; 
    }
    public static byte[] StringToByte(string InString) {
    string[] ByteStrings;
    ByteStrings = InString.Split(" ".ToCharArray());
    byte[] ByteOut;
    ByteOut = new byte[ByteStrings.Length];
    for (int i = 0;i<=ByteStrings.Length-1;i++) {
    ByteOut[i] = Convert.ToByte(("0x" + ByteStrings[i]),16);

    return ByteOut;
    }
    }
      

  3.   

    兄弟不是这样!那上面的那个不是字符串,是内存的形式是byte
      

  4.   

    60 00 03 00 05 00 07 08 00 20 38 00 00 00 00 00 1e 35 00 00
    这个不是字符串就是byte我存在里面也是byte显示,我现在该怎么存?
      

  5.   

    你这个是要以16进制的形式来查看数据把,你在debug的时候会有一个以十六进制显示的按钮,在vs的最上方菜单里面。
      

  6.   

    string str = "60 00 03 00 05 00 07 08 00 20 38 00 00 00 00 00 1e 35 00 00";
    byte[] data = strToToHexByte(str);        private static byte[] strToToHexByte(string hexString) 
            { 
                hexString = hexString.Replace(" ", ""); 
                if ((hexString.Length % 2) != 0) 
                    hexString += " "; 
                byte[] returnBytes = new byte[hexString.Length / 2]; 
                for (int i = 0; i < returnBytes.Length; i++) 
                    returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16); 
                return returnBytes; 
            }
      

  7.   

    写的时候这么写
    byte[] buffer = new byte[] {0x00,0xFF,0x2F,0x00 };
      

  8.   

    兄弟怎么弄?我先把转换为16进制然后在存入byte?我郁闷了!
      

  9.   

         byte[] _TempBytes =new byte[]{0x60,0x00,0x03,0x00,0x05,0x00,0x07,0x08,0x00,0x20,0x38,0x00,0x00,0x00,0x00,0x00,0x1e,0x35,0x00,0x00};            byte[] data=new byte[1024];            Array.Copy(_TempBytes,data,_TempBytes.Length);
    这样?