c# – Binary to ASCII character in C #

Question:

A binary code is entered into the program (For example: 10101001010100), you need to translate it into ASCII characters (string)

Answer:

Perhaps something like this will do

http://ideone.com/14GcZQ

using System;
using System.Text.RegularExpressions;

public class Test
{
    public static void Main()
    {
        var a = "10101001010100";
        Console.WriteLine(Regex.Replace(a, "[01]{7}", m => ((char)Convert.ToByte(m.Value, 2)).ToString()));
    }
}

But if performance is important, it might be worth considering another method.

Scroll to Top