0

This is how I am getting my encoded string in a textblock :.

BitArray encoded = huffmanTree.Encode(input);
foreach (bool bit in encoded)
{
    tb2.Text += ((bit ? 1 : 0) + "");
}

Now, How should I create and save this encoded string in a compressed binary file?

Chubosaurus Software
  • 8,133
  • 2
  • 20
  • 26
  • 2
    You could convert the bit array to a byte array and write the byte array to a file. – Nate Diamond Oct 29 '14 at 17:19
  • Thnx.I'd really appreciate if u provide me code to covert it byte array n save in binary file. – Shahin Ahmed Oct 29 '14 at 17:44
  • 1
    This is where google-fu and research on SO comes into play. I'll give you some links, but you'll have to put them together. [Converting BitArray to Byte Array](http://stackoverflow.com/questions/560123/convert-from-bitarray-to-byte) and [Reading and Writing files in Windows Store apps](http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh758325.aspx). In the latter, check out `FileIO.WriteBufferAsync`. – Nate Diamond Oct 29 '14 at 17:46
  • The second answer to [this question](http://stackoverflow.com/questions/560123/convert-from-bitarray-to-byte) shows how to create a byte array from a `BitArray`. From there, you can write to a file with [File.WriteAllbytes](http://msdn.microsoft.com/en-us/library/system.io.file.writeallbytes(v=vs.110).aspx). – Jim Mischel Oct 30 '14 at 03:13

0 Answers0