Click here to Skip to main content
15,891,567 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:
C#
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);
        }
Posted
Updated 7-Dec-13 15:08pm
v2
Comments
BillWoodruff 7-Dec-13 22:48pm    
You might start here:

http://www.codeproject.com/search.aspx?q=c%23+huffman&doctypeid=1%3b2%3b3%3b13%3b9%3b10%3b14

... and here ...

http://rosettacode.org/wiki/Huffman_coding#C.23

1 solution

Hi
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
 
v2

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