Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please post code in C language. Lab 3-Bitwise Ops - Huffman Encoding/Decoding In this lab, each student is to write a prompt-driven program called p3.c
please post code in C language.
Lab 3-Bitwise Ops - Huffman Encoding/Decoding In this lab, each student is to write a prompt-driven program called p3.c that encodes a text string using Huffman Encoding. The student should gain an understanding of: - Storage Types and Binary Representations - Bitwise Operators: AND, OR, and Shifting - Efficiently Storing Non-byte-size Values - Formatted Input and Output Strings - Displaying Binary, Octal and Hexadecimal values Background Huffman Encoding is a lossless compression technique which takes a string of symbols with a known symbol probability and uses those probabilities to produce new symbols whose variable length is determined by the frequency of occurrence of each symbol (like a similar but much improved Morse Code). When the new symbols are transmitted in a system with the given symbol probabilities, it will produce minimal length transmission sequences. For this project you will be given the Huffman code assuming the following symbol probabilities for English text: The program should prompt the user to enter whether they wish to encode or decode data. Spring 2023 ECE 2220 System Programming Concepts 2 of 5 If encoding is desired, the program should ask the user to input a string only of Alphabetic characters terminated with a special EOT symbol, ' [ ', with a maximum length of 64 characters. All non-alphabetic symbols should be ignored, and all lower-case letters should be converted to upper case. If decoding is desired, the program should ask the user to input a string of Hexadecimal characters, ' 0 to 1F, with a maximum length of 64 characters. The program should continue to input and encode strings until the string 'quit' is input. Encoding Operation The input string should be encoded using the following Huffman code symbols: Note: The order of these codeword bits is very important. To properly distinguish and decode a group of symbol bits, they must be read from left to right. That is an ' A ' should be decoded by reading in order 0001. The character codes above must be stored one after another in an array of 16-bit integers, with all bits being used to store code bits. The resulting code should be stored in the minimum number of integers - not one letter integer. Therefore, some code symbol's bits will be stored in two different integers, where indexing the word and bits in the word will be necessary. For example, if the first three letters of the input data were "XYZ [" they should be stored as: The first integer of the code, Codeword [0], should contain the number of code integers used to store the code (excluding this first integer.) Notice that the difficulty in this program is simply that the Huffman code is not an equallength code. Therefore, code symbols will spread across the natural byte boundary of the computer. Output The program should echo the string entered and then display the binary, hexadecimal, and octal values of each codeword integer which includes an EOT symbol, ' [ , as shown below. Example Output After the user is prompted for string to encode, Enter String: Clemson Tigers! the program should display the following information: String to Encode: CLEMSONTIGERS Codeword [0]=4 Codeword [1] =011110100000110107 AOD 0075015 Codeword[2] =11101001000001000E9040164404 Codeword[3] =0111000110000101071850070605 Codeword [4]=1101010011000101 0xD4C5 0152305 Note, the location of each character in the codeword string is shown below: Codeword[1] =0111101000001101 M E L C Codeword [2] =1110100100000100 T N O S M Codeword[3] =0111000110000101 R E G I T Codeword [4]=1101010011000101[ S R Codeword[1]Codeword[2]Codeword3]=Codeword[4]==0111101000001101=1110100100000100=111000110000101=110101001100010107A0D0E904071850D4C50075015016440400706050152305 Notice that it takes only eight bytes to store this string, whereas it takes fourteen in ASCII, but of course, it's much "uglier" since the codewords are not equal sizes. Decoding Operation The programmer can assume that the string of characters input has been encoding using the method above. The program should input the hex characters as an array of sixteen-bit values, groups of four characters, as given above. Therefore, if the string input is "7A0DE9047185D4C5", the program should store the characters as Codeword [0]=0111101000001101 Codeword [1]=1110100100000100 Codeword [2]=0111000110000101 Codeword [3]=1101010011000101 The codewords should then be decoded using the codewords above in order to produce the output string Decode String = "CLEMSONTIGERS" Remember that the code bits are store from least to most significant bits, e.g. the codeword for ' L ' is 00001 and is stored in b4b3b2b1b0 as 10000 , as shown above. Further Considerations Your program cannot use string functions to construct your code words; it must use a short int and bitwise operators to manipulate bits of the short int codewordsStep 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