How do you convert a string to ascii to binary in C#?

This is very easy to do with C#.

var str = "Hello world";

With LINQ
foreach (string letter in str.Select(c => Convert.ToString(c, 2)))
{
  Console.WriteLine(letter);
}

Pre-LINQ
foreach (char letter in str.ToCharArray())
{
  Console.WriteLine(Convert.ToString(letter, 2));
}

Leave a Comment