C#十六进制转换为char [英] C# Hexadecimal to char
本文介绍了C#十六进制转换为char的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个长度为4的十六进制字符串,例如 003a。
I have a hexidecimal string with a length of 4, such as "003a".
将其转换为char的最佳方法是什么?首先转换为字节,然后转换为char?
What is the best way to convert this into a char? First convert to bytes and then to char?
推荐答案
尝试以下操作:
(char)Int16.Parse("003a", NumberStyles.AllowHexSpecifier);
或
System.Convert.ToChar(System.Convert.ToUInt32("003a", 16));
或
string str = "";
for(int i = 0; i<myHex.Length; i += 4)
str += (char)Int16.Parse(myHex.Substring(i, 4),
NumberStyles.AllowHexSpecifier);
这篇关于C#十六进制转换为char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文