string str = "hello"; byte[] array = new byte[1]; array = System.Text.Encoding.ASCII.GetBytes(str); //把str的每个字符转换成ascii码 int asciicode1 = (short)(array[0]);//h 的ascii码 int asciicode2 = (short)(array[1]);//e 的ascii码 int asciicode3 = (short)(array[2]);//l 的ascii码 int asciicode4 = (short)(array[3]);//l 的ascii码 int asciicode5 = (short)(array[4]);//o 的ascii码 int asciicode = 0; for (int i = 0; i < array.Length; i++) { += array[i]; //str 的ascii码 }
byte[] array = new byte[1]; array[0] = (byte)(Convert.ToInt32(104));//ASCII码强制转换二进制 string ret=Convert.ToString(System.Text.Encoding.ASCII.GetString(array));