Mohanapriya R Mohanapriya R
Updated date Aug 27, 2024
In this article, we will learn the basics of Binary (1s and 0s) into Strings using C#.
  • 2.1k
  • 0
  • 0

Binary to String Conversion in C#:

Binary data is a sequence of 1s and 0s, while strings are sequences of characters. In C#, the Encoding class provides methods to facilitate this conversion.

using System;
using System.Text;

class BinaryToStringConverter
{
    static void Main()
    {
        // Binary data as an array of bytes
        byte[] binaryData = { 01001000, 01100101, 01101100, 01101100, 01101111, 00100000, 01000011, 01011101 };

        // Convert binary data to string using UTF-8 encoding
        string resultString = Encoding.UTF8.GetString(binaryData);

        // Display the output
        Console.WriteLine("Binary to String Conversion Result: " + resultString);
    }
}

Output:

Binary to String Conversion Result: Hello C]

Comments (0)

There are no comments. Be the first to comment!!!