在C#中将十六进制字符串转换为其数值 [英] Convert hexadecimal string to its numerical values in C#
本文介绍了在C#中将十六进制字符串转换为其数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的表单上有一个文本框。我想将0x31作为字符串写入我的文本框,然后当我单击按钮时,我想将此字符串转换为0x31作为十六进制值。
i have a text box on my form. I want to write "0x31" as a string to my textbox and then when i clicked a button, i want to convert this string to 0x31 as a hexadecimal value.
我可以将此字符串转换为十六进制值吗?
How can i convert this string to hexadecimal value?
推荐答案
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);
}
示例来自: http://msdn.microsoft.com/en-us/library/bb311038.aspx
这篇关于在C#中将十六进制字符串转换为其数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文