Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C program in main.c in directory unzipper that will be compiled into an executable unzip - per. Your program will read in a

Write a C program in main.c in directory unzipper that will be compiled into an executable unzip-
per. Your program will read in a series of bytes in hexadecimal notation, representing the decoding table
needed to decompress a piece of compressed text.
Input
Your program will read its input from stdin. The first line contains a single byte denoting the number of
entries T in the decoding table. This byte is to be interpreted as an unsigned integer. If T is 0, then it is to
be interpreted as 256. This is followed by T lines, each encoding a table entry and consisting of three
items: the character, C, that is encoded; the length, L,(in bits) of the
encoding; and the encoding, E, which is bit sequence of L bits. After
the table entries there are four bytes encoding the length of the com-
pressed bitstream to be decoded. For Problem 1, these four bytes are
0, indicating there is no compressed data to follow. In Problem 2,
these four bytes will not be all 0s.
Each entry is encoded as a three byte (24-bit) bitstream, where the bits
in each byte are ordered most-significant (first bit) to least significant
(last bit). The first 8 bits encode the character (C). The next 4 bits en-
code length, L (an unsigned integer), and the first L bits of the remain-
ing 12 bits are the compressed encoding E, of character C. The three
bytes are encoded in the input in hexadecimal. (Hint: Use scanf to
read the bytes). For the hexadecimal, use the format specifier with
"%x". On the right is an example of a table for encoding the string
Hello World!
, Observe that in this case the encodings for the
characters are between 2 and 4 bits long instead of the full 8 bits per
byte.
Processing
Your program will need to read in the table and output it in a human-
readable form.
The decoding table will have at most 256 entries. (Use an array
of structs to store the table, as it will be needed for Problem 2.)
For each entry, read in the 3 bytes and interpret the 24-bit bit-
stream as described above.
The encoding of each character will be at most 12 bits. Any extra bits can be ignored.
Output
All output should be performed to stdout. The output must be exactly as specified. The output consists
of T lines, one line per entry in the table. Each line should be terminated by a new-line character. The
entries should be displayed in the same order as the input.
Each entry has the following format:
C : L E2
where
C is the character in hexadecimal using the format 0x%2.2x
L is a decimal integer, using the format %d
E2 is the binary representation of the encoding, it should be exactly L characters (0s and 1s) long.
(See example)
0x0a
0x210x300x00
0x570x420x00
0x480x430x00
0x6c 0x240x00
0x6f 0x380x00
0x0a 0x3a 0x00
0x650x4c 0x00
0x640x4d 0x00
0x200x4e 0x00
0x720x4f 0x00
0x000x000x000x00
Examples
Input (Ex 1) Output (Ex 1) Input (Ex 2) Output (Ex 2)
0x0a
0x210x300x00
0x570x420x00
0x480x430x00
0x6c 0x240x00
0x6f 0x380x00
0x0a 0x3a 0x00
0x650x4c 0x00
0x640x4d 0x00
0x200x4e 0x00
0x720x4f 0x00
0x000x000x000x00
0x21 : 3000
0x57 : 40010
0x48 : 40011
0x6c : 201
0x6f : 3100
0x0a : 3101
0x65 : 41100
0x64 : 41101
0x20 : 41110
0x72 : 41111
0x0d
0x6b 0x100x00
0x6a 0x280x00
0x690x3c 0x00
0x680x4e 0x00
0x670x5f 0x00
0x0a 0x6f 0x80
0x780xcf 0xc0
0x610xcf 0xc1
0x620xbf 0xc2
0x630xaf 0xc4
0x640x9f 0xc8
0x650x8f 0xd0
0x660x7f 0xe0
0x000x000x000x00
0x6b : 10
0x6a : 210
0x69 : 3110
0x68 : 41110
0x67 : 511110
0x0a : 6111110
0x78 : 12111111000000
0x61 : 12111111000001
0x62 : 1111111100001
0x63 : 101111110001
0x64 : 9111111001
0x65 : 811111101
0x66 : 71111111

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions