Thread: Trying to decpmpress a coded file

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    118

    Trying to decpmpress a coded file

    i am writting a code to decompress a huffman file and i am a little bit confused.I am using the amount of charracters that was written into file to help me determine when to stop reading.I am a little bit confused because it seems like a maze
    Code:
    void HuffmanENcodding :: decompressFile(ifstream &file){
        file.open("Thecompressed.txt");
        string text;
        unsigned char byte; //used to store a byte when read 
        int length=8;
        int shift=7;
        int  direction; //used to determine whether to go left or right
        Node *root=new Composite(); //gets the top of my tree
        root=getRoot();
          for(int i=0;i<characterslenght;i++){
          if(length==8){
           byte=file.get();
          }
          
          while(length)
           direction=(byte>>shift) &1; //getting the bit starting from the msb
           
           getchild(root,direction);
    
    
    
    
      }
    
    
    }
    above is a sample code

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    You don't have to use a literal tree to unpack the compression. In the tutorial the tree diagram is supposed to communicate the following:

    You've encoded each character in a set number of bits. We can call it a part of the compression. You need to collect all of the bits in one part, and look up the corresponding character in a table. Remember when you used the prefix property (bit 0 in the tutorial), encountering the bit means that you should store it, decode, and start on a new part.
    Last edited by whiteflags; 02-20-2012 at 05:12 PM.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    118
    Quote Originally Posted by whiteflags View Post
    You don't have to use a literal tree to unpack the compression. In the tutorial the tree diagram is supposed to communicate the following:

    You've encoded each character in a set number of bits. We can call it a part of the compression. You need to collect all of the bits in one part, and look up the corresponding character in a table. Remember when you used the prefix property (bit 0 in the tutorial), encountering the bit means that you should store it, decode, and start on a new part.
    How can i collect all the bits in one part when there is no fixed size fot the number of bits a character is

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Quote Originally Posted by sigur47 View Post
    How can i collect all the bits in one part when there is no fixed size fot the number of bits a character is
    There is, really. The maximum number of bits required to encode a character is also the maximum amount of storage you need to store the code. If you don't want to do that, which is a feeling I understand, you can count the bits.

    1110

    Three 1 bits is unique to every other code, and must map to some character. Maybe 3 could be used as an index in a big decoding table.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. STL vs hand-coded
    By franziss in forum C++ Programming
    Replies: 18
    Last Post: 09-20-2005, 04:10 AM
  2. Hows my new site I hand coded?
    By v3ct0r_sect0r in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 03-24-2004, 02:54 PM
  3. Coded Music
    By face_master in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-04-2002, 04:09 PM
  4. HEX and BCD coded file READING !!
    By mehuldoshi in forum C Programming
    Replies: 2
    Last Post: 07-31-2002, 07:23 AM