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 8955563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:35:24+00:00 2026-06-15T14:35:24+00:00

I’m trying to learn the Inflate algorithm by implementing it in Java so that

  • 0

I’m trying to learn the Inflate algorithm by implementing it in Java so that I may then implement it in assembly for a CPU with a very restricted instruction set.

I’m having trouble reading in the correct code lengths from the file after reading in the number of literal, distance, and length codes.
I’m following through an implementation as described here, where they provide an example .gz file gunzip.c.gz. After reading in the gzip headers, the following is the first 56 bits of the first (and if I’m reading it correctly, only) compressed data block:

10111101 00011011 11111101 01101111 11011010 11001000 11110010

I will refer to bits in a byte by the following offsets: [76543210]
The first byte 10111101 contains the end of block at offset 0, offset 21 contain the two bits that determine the block type.
In this case, this is the last block, and it is a dynamic Huffman Tree.

The following bits to be interpreted are the number of literal (5 bits), distance (5 bits), and length (4 bits) codes. They are read in as follows:

10111101 -> 10111XXX -> 23 (literal)
00011011 -> XXX11011 -> 27 (distance)
00011011 11111101 -> 000XXXXX XXXXXXX1 -> 1000 -> 8 (length)

After this point, I’m having trouble. The next 36 bits should be 12 sets of 3 bits that indicate the code lengths.
From the bytes above, I see (interpreted as little-endian):

110 111 111 011 011 010 011 011 100 100 101 100
3   7   7   6   6   2   6   6   1   1   5   1

But I expect (as indicated in the link above)

101 011 011 110 110 110 110 110 110 001 001 001
5   6   6   3   3   3   3   3   3   4   4   4

I can’t see any way to get these values from the file. I must be misinterpreting how the bits should be read. Given a byte with a 5 bit value followed by a 3 bit value, [CBA43210] I would read it as 01234 and ABC.

Is the article wrong in what the correct code lengths should be, or more likely, am I wrong on how they should be interpreted?

  • 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-06-15T14:35:25+00:00Added an answer on June 15, 2026 at 2:35 pm

    bits themselves are read LSB to MSB as illustrated in figure 6:

    <----
    87654321
    

    (from the document linked by the question) indicates that

    [CBA43210] I would read it as 01234 and ABC.

    (from the question itself) is correct.

    Little-endian means that least significant digits (here, bits) are stored or read (here, interpreted) first.

    However, 01234 and ABC themselves are in little-endian, so the byte 110 11000 would be interpreted as 3 3, not 24 6.

    This means the five, five and four bits in

    10111101 00011011 ...
    

    are

    xxx11101 => 11101  => 29
    101xxxxx
    xxxxxx11 => 11 101 => 29
    xx0110xx => 0110   => 6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

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.