2013-02-23 120 views
0

嗨,大家好,我想從ASCII碼轉換成普通代碼 因爲我做的是從正常的代碼轉換爲ASCII碼的方法,我想在這裏REVERS它 是我的方法來轉換爲ASCII如何將ascii代碼轉換爲c#中的正常代碼?

public string CreatSerial() 
    { 
     string serial = ""; 
     string P1, P2 = ""; 
     string Befor_Serial = GetDeviceSerial().Trim() + 5; 
     P1 = Befor_Serial.Substring(0, Befor_Serial.Length/2); 
     P2 = Befor_Serial.Substring(Befor_Serial.Length/2); 
     Befor_Serial = P2 + "ICS" + P1; 
     char[] strarr = Befor_Serial.ToCharArray(); 
     Array.Reverse(strarr); 
     serial = new string(strarr); 
     byte[] asciiBytes = Encoding.ASCII.GetBytes(serial); 
     serial = ""; 
     foreach (byte b in asciiBytes) 
     { 
      serial += b.ToString(); 
     } 
     return serial; 
    } 
+1

什麼是「正常」? – 2013-02-23 16:07:32

+0

不僅僅是一個重複但實際上相同的標題,直到「正常」這個詞。驚訝的是它沒有出現在你提問之前進行的搜索中。 – 2013-02-23 16:19:48

回答

0

您創建的字符串是不可逆的。從MSDN

byte[] bytes = {0, 1, 14, 168, 255}; 
foreach (byte byteValue in bytes) 
    Console.WriteLine(byteValue.ToString()); 
// The example displays the following output to the console if the current 
// culture is en-US: 
//  0 
//  1 
//  14 
//  168 
//  255 

請看下面的例子。如果你把這個數字加在一起,你會得到0114168255。沒辦法從中獲得字節。你可以做的是使用Byte.ToString("x")來代替。它將產生底層字節值的十六進制表示。它總是長度爲2.

相關問題