次のコードを使用して、指定された 16 進数文字列をデコードできました。C# では、そのライブラリ関数を使用して、16 進数値を ASCII、Unicode、ビッグエンディアン Unicode、UTF8、UTF7、UTF32 にデコードできました。16 進数文字列を ROT13、UTF16、西ヨーロッパ、HFS Plus などの他のデコード スタイルに変換する方法を教えてください。
{
string hexString = "68656c6c6f2c206d79206e616d6520697320796f752e";
byte[] dBytes = StringToByteArray(hexString);
//To get ASCII value of the hex string.
string ASCIIresult = System.Text.Encoding.ASCII.GetString(dBytes);
MessageBox.Show(ASCIIresult, "Showing value in ASCII");
//To get the Unicode value of the hex string
string Unicoderesult = System.Text.Encoding.Unicode.GetString(dBytes);
MessageBox.Show(Unicoderesult, "Showing value in Unicode");
}
public static byte[] StringToByteArray(String hex)
{
int NumberChars = hex.Length / 2;
byte[] bytes = new byte[NumberChars];
using (var sr = new StringReader(hex))
{
for (int i = 0; i < NumberChars; i++)
bytes[i] =
Convert.ToByte(new string(new char[2] { (char)sr.Read(), (char)sr.Read() }), 16);
}
return bytes;
}