Convert string to Byte Array

Write a program to Convert string to Byte Array.

Solution

using System;
using System.Text;

namespace ByteArray
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine("Enter a string:");
            var str = Console.ReadLine();

            var bytesArr = Encoding.ASCII.GetBytes(str);

            Console.WriteLine("Byte array:");
            foreach (var b in bytesArr)
            {
                Console.WriteLine(b);
            }
            Console.ReadLine();
        }

    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *