1、字母轉換成ASCII碼
1 string str = "hello"; 2 byte[] array = new byte[1]; 3 array = System.Text.Encoding.ASCII.GetBytes(str); //把str的每個字符轉換成ascii碼 4 5 int asciicode1 = (short)(array[0]);//h 的ascii碼 6 int asciicode2 = (short)(array[1]);//e 的ascii碼 7 int asciicode3 = (short)(array[2]);//l 的ascii碼 8 int asciicode4 = (short)(array[3]);//l 的ascii碼 9 int asciicode5 = (short)(array[4]);//o 的ascii碼 10 11 int asciicode = 0; 12 for (int i = 0; i < array.Length; i++) 13 { 14 asciicode += array[i];//str 的ascii碼 15 }
2、ASCII碼換成字母
1 byte[] array = new byte[1]; 2 array[0] = (byte)(Convert.ToInt32(104));//ASCII碼強制轉換二進制 3 string ret=Convert.ToString(System.Text.Encoding.ASCII.GetString(array));
3、ASCII碼對照表