Concatenating bits in a single string

advertisements

I want to concat some bits into one. I have this method:

public BitArray Encode(string source)
{
    List<bool> encodedSource = new List<bool>();

    for (int i = 0; i < source.Length; i++)
    {
        List<bool> encodedSymbol = this.Root.Traverse(source[i], new List<bool>());
        encodedSource.AddRange(encodedSymbol);
    }

    BitArray bits = new BitArray(encodedSource.ToArray());

    return bits;
}

It is returning me 0/1 binary bits, now I have this code to show me the output:

foreach (bool bit in encoded)
{
    MessageBox.Show((bit ? 1 : 0) + "");
}

Now I am just showing a MessageBox for each bit, but how can I just concat all the bits into one MessageBox , it may be a silly question but I can't wrap my head around it.


var bitString = string.Concat(encoded.Select(bit => bit ? "1" : "0"))