您的位置:首页 > 其它

如何:在十六进制字符串与数值类型之间转换

2016-08-31 21:04 316 查看
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);

}

 
 
 
string hexValues = "48 65 6C 6C 6F 20 57 6F 72 6C 64 21";string[] hexValuesSplit = hexValues.Split(' ');foreach (String hex in hexValuesSplit)

{

    // Convert the number expressed in base-16 to an integer.

    int value = Convert.ToInt32(hex, 16);

    // Get the character corresponding to the integral value.

    string stringValue = Char.ConvertFromUtf32(value);

    char charValue = (char)value;

    Console.WriteLine("hexadecimal value = {0}, int value = {1}, char value = {2} or {3}",

                        hex, value, stringValue, charValue);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: