2011-05-18 36 views
-1

我有以下代碼:STRING TO HEX如何添加一個向量ob字節?

string s = "2563MNBJP89256666666685755854"; 
      Byte[] bytes = encoding.GetBytes(s); 
      string hex = ""; 
      foreach (byte b in bytes) 
      { 
       int c=b; 
       hex += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(c.ToString())); 
      } 

它打印出的十六進制值。我如何將它添加到像這樣的矢量ob字節中?

new byte [0x32,0x35..] 

In hex I have : 323536...。等等。下一步是to add then in a byte[] vector in the following format 0x32,0x35..and so on; How to do this?

THX

+0

http://stackoverflow.com/questions/2575468/string-to-byte-array爲C++部分 – Mat 2011-05-18 07:46:33

+0

請閱讀有關如何使用此FAQ的常見問題網站... – 2011-05-18 08:17:32

+0

你的意思是一個字節數組?你的意思是base64嗎?你是指另一串十六進制數字字符? – Jodrell 2011-05-18 08:20:03

回答

1

是不是bytes已經列表你想要的字節數?

+0

如何chech那?如何打印字節值? – daniel 2011-05-18 08:47:27

+0

@daniel:您的代碼已經打印出字節值。 – 2011-05-18 08:48:33

+0

不,這是不一樣的。值是不同的:)。 – daniel 2011-05-18 08:48:57

0

C#:System.Text.Encoding.ASCII.GetBytes("test")

+0

這不是一回事。我測試過它:) – daniel 2011-05-18 07:45:42

+0

有什麼不一樣的?你得到與每個字符相關的字節值。 – Botz3000 2011-05-18 07:49:58

0

對於C#你可以嘗試

System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding(); 
Byte[] bytes = encoding.GetBytes(strVar);//strVar is the string variable 
+0

有沒有ASCII,字符串,字節和其他轉換器的鏈接?我知道有一個..但我只是可以;找到鏈接 – daniel 2011-05-18 07:49:09