Answered step by step
Verified Expert Solution
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 then it is to
be interpreted as This is followed by T lines, each encoding a table entry and consisting of three
items: the character, C that is encoded; the length, Lin 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 bit bitstream, where the bits
in each byte are ordered mostsignificant first bit to least significant
last bit The first bits encode the character C The next bits en
code length, L an unsigned integer and the first L bits of the remain
ing 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 characters, but it is recommended to simply read in one byte at a time as the bitstream is being
decoded.If N is not do not output the decoding table as described in Problem and output the text from
the decompressed bitstream instead.
To decompress a character from the bitstream:
o Start with an encoding D of length bits
o In a loop Note: D can be at most 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 if the N is oth
erwise, output the decompressed text. See example.
Example
Input Output Hello World!
xa
xxx
xxx
xxx
xc xx
xf xx
xa xa x
xxc x
xxd x
xxe x
xxf x
xxxxe
xc xxcxd xdx
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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started