C# - Hex To String
public String HexToString(String hexString)
{
int value;
string stringValue = null;
char charValue;
string _strOutput = null;
string hexValues = hexString;
string _leftPosition = null;
Int32 _subLength = 0;
string _tmp = null;
string[] hexValuesSplit;
for (Int32 _i = 0; _i < hexValues.Length; _i=(_i+_subLength))
{
_leftPosition = hexValues.Substring(_i, 1);
switch (_leftPosition.ToUpper())
{
case "E":
_subLength = 3;
break;
case "F":
_subLength = 4;
break;
case "0":
_subLength = 4;
break;
default:
_subLength = 2;
break;
}
_tmp += hexValues.Substring(_i, _subLength) + " ";
}
hexValuesSplit = _tmp.Trim().Split(' ');
foreach (String hex in hexValuesSplit)
{
// Convert the number expressed in base-16 to an integer.
value = Convert.ToInt32("0" + hex, 16);
// Get the character corresponding to the integral value.
stringValue = Char.ConvertFromUtf32(value);
charValue = (char)value;
//Console.WriteLine("hexadecimal value = {0}, int value = {1}, char value = {2} or {3}", hex, value, stringValue, charValue);
_strOutput += stringValue;
}
return _strOutput;
}
{
int value;
string stringValue = null;
char charValue;
string _strOutput = null;
string hexValues = hexString;
string _leftPosition = null;
Int32 _subLength = 0;
string _tmp = null;
string[] hexValuesSplit;
for (Int32 _i = 0; _i < hexValues.Length; _i=(_i+_subLength))
{
_leftPosition = hexValues.Substring(_i, 1);
switch (_leftPosition.ToUpper())
{
case "E":
_subLength = 3;
break;
case "F":
_subLength = 4;
break;
case "0":
_subLength = 4;
break;
default:
_subLength = 2;
break;
}
_tmp += hexValues.Substring(_i, _subLength) + " ";
}
hexValuesSplit = _tmp.Trim().Split(' ');
foreach (String hex in hexValuesSplit)
{
// Convert the number expressed in base-16 to an integer.
value = Convert.ToInt32("0" + hex, 16);
// Get the character corresponding to the integral value.
stringValue = Char.ConvertFromUtf32(value);
charValue = (char)value;
//Console.WriteLine("hexadecimal value = {0}, int value = {1}, char value = {2} or {3}", hex, value, stringValue, charValue);
_strOutput += stringValue;
}
return _strOutput;
}