Strange results when converting from byte array to string
问题 I get strange results when converting byte array to string and then converting the string back to byte array. Try this: byte[] b = new byte[1]; b[0] = 172; string s = Encoding.ASCII.GetString(b); byte[] b2 = Encoding.ASCII.GetBytes(s); MessageBox.Show(b2[0].ToString()); And the result for me is not 172 as I'd expect but... 63. Why does it happen? 回答1: Why does it happen? Because ASCII only contains values up to 127. When faced with binary data which is invalid for the given encoding, Encoding