Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compression > #1963

Re: Beginner's question about RFC 1951

From Ian Clifton <ian.clifton@chem.ox.ac.uk>
Newsgroups comp.compression
Subject Re: Beginner's question about RFC 1951
Date 2013-05-31 15:33 +0100
Organization Oxford University
Message-ID <koacc4$udc$1@news.ox.ac.uk> (permalink)
References <koa84l$ia$1@dont-email.me>

Show all headers | View raw


Christoph-Simon Senjak <css@uxul.de> writes:

> Hello.
>
> I am currently trying to understand RFC 1951. I used the example file
> http://zlib.net/zpipe.c to generate a Deflate stream. I use the
> following program to dump the binary representation of the created
> deflate stream:
>
> /* toBin.c */
> #include <stdio.h>
>
> void toString (int c, char* out) {
>   int i;
>   for (i = 0; i < 8; ++i) {
>     out[i] = ((c >> i) % 2) == 0 ? '0' : '1';
>   }
> }
>
> int main (void) {
>   int c;
>   char ts[9]; ts[8] = 0;
>   while ((c = getchar()) != EOF) {
>     toString(c, ts);
>     printf("%s.", ts);
>   }
> }
>
> Now, when running
>
> $ echo "Hello World" | ./zpipe | ./toBin
>
> I get a String starting with
>
> 00011110.00111001.11001111.00010010.10110011.
>
> If I understand correctly, the leading bits 000 means "not the last
> block" and "no compression", according to RFC 1951. The next five bits
> are ignored, and then two times sixteen bits are used to indicate the
> length of the uncompressed block, and the should be the complement of
> each other, but as you can see, they are not.
>
> I thought of maybe interpreting the bit-endianness wrong, but even if
> I reverse the first byte, it starts with 011, and the compression
> method 11 is reserved, according to RFC 1951.
>
> What am I missing? Sorry if this is a stupid question, but I am trying
> to understand the RFC, and I am not yet familiar with everything.

I’m not familiar with C, so I can’t comment on how your “toBin” program
works; but whenever I’ve delved into things in this way, I’ve found you
need to be absolutely sure you know which bit‐positions in your bytes
(however you’re choosing to look at them) correspond to which
bit‐positions in the abstract standard—any room for doubt, and you’re
sure to get confused, in my experience!
-- 
Ian ◎

Back to comp.compression | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Beginner's question about RFC 1951 Christoph-Simon Senjak <css@uxul.de> - 2013-05-31 15:25 +0200
  Re: Beginner's question about RFC 1951 Ian Clifton <ian.clifton@chem.ox.ac.uk> - 2013-05-31 15:33 +0100
    Re: Beginner's question about RFC 1951 Christoph-Simon Senjak <css@uxul.de> - 2013-05-31 17:35 +0200
      Re: Beginner's question about RFC 1951 Christoph-Simon Senjak <css@uxul.de> - 2013-05-31 23:36 +0200

csiph-web