Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code in C: Your program will read its input from stdin. The first line contains a single byte denoting the number of entries T in

Code in C: 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.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). the four bytes after the table encode an integer,
N, in big endian byte order, denoting the number of compressed characters encoded in the bitstream that
follows. The rest of the input consists of zero or more bytes (in hexadecimal representation) encoding a
bitstream, using the same bit order as the encoding of the table. For convenience, no line will be longer
than 60 characters, but it is recommended to simply read in one byte at a time as the bitstream is being
decoded.If N is not 0, do not output the decoding table as described in Problem 1, and output the text from
the decompressed bitstream instead.
To decompress a character from the bitstream:
o Start with an encoding D of length 0(0 bits)
o In a loop (Note: D can be at most 12 bits long)
Add the next bit from the bitstream to D
Search the table for encoding D. Both bit pattern and length must match
If found, break
o Output corresponding character C.
Once the expected number of characters is
decoded, stop.
All encodings are prefix free, meaning that no
encoding is a prefix of another encoding.
Output
Same output format as for Problem 1 if the N is 0, oth-
erwise, output the decompressed text. (See example.)
Example
Input Output = Hello World!
0x0a
0x210x300x00
0x570x420x00
0x480x430x00
0x6c 0x240x00
0x6f 0x380x00
0x0a 0x3a 0x00
0x650x4c 0x00
0x640x4d 0x00
0x200x4e 0x00
0x720x4f 0x00
0x000x000x000x0e
0x3c 0x590xc50x3d 0xd10x68
Hello World!
i am having trouble in processing the last line hexadecimals. we are to store all binary conversions into one array and then parse it. when printing using printBinary, it prints one bit at a time. I need to store the bits into an unsigned short.
image text in transcribed

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

Beginning PostgreSQL On The Cloud Simplifying Database As A Service On Cloud Platforms

Authors: Baji Shaik ,Avinash Vallarapu

1st Edition

1484234464, 978-1484234464

More Books

Students also viewed these Databases questions