public static void Main()
string text = "Привет, человеки!";
string hex = TextToHex(text);
Console.WriteLine(HexToText(hex));
private static string TextToHex(string value)
byte[] bytes = new byte[value.Length * 2];
System.Buffer.BlockCopy(value.ToCharArray(), 0, bytes, 0, bytes.Length);
return String.Join("", bytes.Select(b => b.ToString("x2")).ToArray());
private static string HexToText(string value)
byte[] data = Enumerable.Range(0, value.Length).Where(x => x % 2 == 0).Select(x => Convert.ToByte(value.Substring(x, 2), 16)).ToArray();
char[] chars = new char[data.Length / 2];
System.Buffer.BlockCopy(data, 0, chars, 0, data.Length);
return new string(chars);