Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6929413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:18:54+00:00 2026-05-27T11:18:54+00:00

I am implementing a program to perform Huffman compression/decompression (for the sake of learning/having

  • 0

I am implementing a program to perform Huffman compression/decompression (for the sake of learning/having fun, so I don’t want to use existing libraries/programs).

I managed to build the compression three, so I have a table with all the characters and their respective compressed representation in bits. For example:

a = 0010
b = 01101
c = 0011
d = 1101
e = 101

Now my idea is to store the bits into a container (e.g., a char or int variable) and then to output them to a file.

I know how to pack/unpack bits into a char or int using bitwise operations. The problem I am facing, however, is that the number of bits in the compressed version won’t match the number of bits I have available.

Suppose I want to compress the string “abc” using the table above. I would start by compressing ‘a’, so packing 0010 into a char variable. Next I would compress ‘b’, but that requires 5 bits, and I only have 4 bits left on my char variable. I could use another variable, but it would become a mess to keep track what variable is using how many bits.

Using int would give me 32 bits to work with, but the same problem would happen once I get close to the limit.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:18:55+00:00Added an answer on May 27, 2026 at 11:18 am

    There is no way around. You have to keep track of the bits left in your storing structure.

    It’s not really a mess. It’s in fact relatively easy to try.
    Just store the upper bits in the remaining storage, and then store the lower ones into the new storage. At each step, you need to know how many bits are left.

    I would also suggest to use uint32 types instead of char, due to their superior storage capacity. It will require less shuffling, and therefore improve speed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to write a program who use collection for implementing a map in
I'm having some trouble implementing DoubleBuffer into my program. Before you faint from the
I'm having some problems implementing an exception system in my program. I found somewhere
I am implementing basic socket program , but in this case i want the
I am currently working on implementing a program based on the huffman algorithm in
I'm implementing a system to send Messages between different parts of a program I'm
I'm implementing a process elevation helper for Windows. It's a program that will run
I'm implementing a program which gets text from various sites and checks which ones
I need to write a program implementing the visitor design pattern. The problem is
I am thinking about implementing a program with finite state automaton in an OOP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.