Write a C program in main.c in directory marsdeel that will be compiled into an executable
marsdecl. Your program will read in a series of bytes in hexadecimal notation and decode the stream
of bytes, outputting the decoded integers.
https://en.wikipedia.org/wiki/Mars Reconnaissance Orbiter
Input
Your program will read its input from stdin. The first line contains a single integer denoting the number
of lines N in the communication. This is followed by N lines, each containing an integer B denoting the
number of bytes on the line, followed by B bytes in hexadecimal notation. (Hint: Use scanf to read
integers and bytes). For the hexadecimal, use the format specifier with "x".
4
3 0x620x69 0x00
4 Oxca Oxfl 0x85 0x38
5 Oxfb Oxff Oxff Oxff Oxfo
5 Oxfc 0x00 0x00 0x000x10
For problem 1, the number of bytes will range from 0 to 5. This will increase for Problems 2. Each line
corresponds to an encoding of a single integer. The first 5
bits represent a 5-bit unsigned integer L, followed by an L-
bit signed integer. The remaining bits are ignored.
10100011101100010001000010000000
Bit Order
The bits are ordered left to right, with the bytes ordered 0
... 3 and the bits in each byte ordered most significant to
least significant bit (in big-endian). E.g., bit 0 in the figure
on the right is the first bit in the stream and is the most
significant bit of byte 0. Bit 31 is the last bit in the stream
and is the least significant bit of byte 3. The bits are to be
processed in increasing order from 0 to 31.
Processing
For each of the N lines, the program must
Length
e.g. 20
.
Bit 0
SignedInteger
e.g. 20-bit int
5
93 bl
10010011101100010001001010001000
Byte 0
12
86
Ignore
Byte 3
Bit 31
Read in the B bytes and unpack the integer.
• The packed integer is stored in the order of most-significant to least significant bit.
The number of bytes can range from 0 up to 5 bytes. If there are 0 bytes, then the line has no
integers to unpack.
The last byte may not be filled. The extra bits can be ignored.
Fig: 1