Click here to Skip to main content
15,793,452 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
I need to know how to compress (read) a file using Huffman Algorithm in c #, because I can do it bit by bit, but I need it to be 1024 bit. Note: sorry for my English.

This is part of my code:
static String BitArrayToStr(BitArray ba)
            byte[] strArr = new byte[ba.Length / 8];

            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

            for (int i = 0; i < ba.Length / 8; i++)
                for (int index = i * 8, m = 1; index < i * 8 + 8; index++, m *= 2)
                    strArr[i] += ba.Get(index) ? (byte)m : (byte)0;

            return encoding.GetString(strArr);
Updated 7-Dec-13 16:08pm
BillWoodruff 7-Dec-13 22:48pm    
You might start here:

... and here ...

1 solution

Please follow of these links you can get your answer after reading these links ;-)

Huffman coding in C#
Implementing the Huffman algorithm as a C# library[^]
Fast and Simple Huffman Compressor[^]
Simple Huffman .Txt File Compression C#

Best Regards.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900