Windows Forms: Convert binary to text in C#

This post will show you how to convert binary to text in C#.NET Windows Forms Application.

To convert binary to string in c#, you can drag the textbox, label and button from your visual studio toolbox to your winform, then layout your UI as shown below.

convert binary to string in c#

Next, Create the BinaryToString method allow you to convert binary to text in c# as the following code.

public string BinaryToString(string data)
    List<byte> bytes = new List<byte>();
    for (int i = 0; i < data.Length; i += 8)
        bytes.Add(Convert.ToByte(data.Substring(i, 8), 2));
    return Encoding.ASCII.GetString(bytes.ToArray());

Finally, Add code to handle the Convert button click event.

private void btnConvert_Click(object sender, EventArgs e)
    txtOutput.Text = BinaryToString(txtInput.Text);

Press F5 to build and run your project, then you can enter the binary code and convert binary to string in c#. In other words, you have created a binary to string converter in c# winforms.