日期:2014-05-18 浏览次数:20901 次
System.Convert.ToString('a',16);// ==>输出 61 byte[] btArr = new byte[]{97,98,99,100}; System.BitConvert.ToString(btArr);// ==>输出 61-62-63-64
------解决方案--------------------
MSDN上的一段代码,相当漂亮:
string input = "Hello World!"; char[] values = input.ToCharArray(); foreach (char letter in values) { // Get the integral value of the character. int value = Convert.ToInt32(letter); // Convert the decimal value to a hexadecimal value in string form. string hexOutput = String.Format("{0:X}", value); Console.WriteLine("Hexadecimal value of {0} is {1}", letter, hexOutput); } /* Output: Hexadecimal value of H is 48 Hexadecimal value of e is 65 Hexadecimal value of l is 6C Hexadecimal value of l is 6C Hexadecimal value of o is 6F Hexadecimal value of is 20 Hexadecimal value of W is 57 Hexadecimal value of o is 6F Hexadecimal value of r is 72 Hexadecimal value of l is 6C Hexadecimal value of d is 64 Hexadecimal value of ! is 21 */