Запись в бинарный файл в шестнадцатеричной системе - C#

Узнай цену своей работы

Формулировка задачи:

в в шестнадцатеричной системе
static void Main(string[] args)
        {
            string aplha = "qwertyuiopasdfghjklzxcvbnm";
            string numbers = "123456789";
            string path = @"C:\.....a";
            byte[] symbols =System.Text.Encoding.Default.GetBytes(numbers);
            foreach (byte element in symbols)
                Console.WriteLine(element);
            DirectoryInfo dir = new DirectoryInfo(path);
            if (!dir.Exists)
                dir.Create();
            using (BinaryWriter writer = new BinaryWriter(File.Open(path+@"\beta.dat", FileMode.OpenOrCreate)))
            {
 
            }

Решение задачи: «Запись в бинарный файл в шестнадцатеричной системе»

textual
Листинг программы
static void Main(string[] args)
{
    string s = "qwertyuiopasdfghjklzxcvbnm";
    const string path = @"C:\dir\file.txt";
    byte[] bytes = System.Text.Encoding.Default.GetBytes(s);
    using (var writer = new StreamWriter(path))
    {
        for (int i=0; i<bytes.Length; i++)
        {
            if (i>0) writer.Write(" ");
            writer.Write("0x{0:X2}", bytes[i]);
        }
    }
}

Оцени полезность:

5   голосов , оценка 4.2 из 5