SlideShare a Scribd company logo
1 of 11
Download to read offline
Write the code in C, here is the template provided:
The input used is:
The output should look exactly like this:
MP2: encoding and decoding (29, 24) Hamming code.
Commands:
enc 3-letters
dec 8-hex-digits
quit
# :Examples for MP2
# : CUt weight 11 00110
Encoding: t U C
0x 00 74 55 43
-------- 01110100 01010101 01000011
P1 : 0
P2 : 0
P4 : 1
P8 : 1
P16: 0
---01110 10001010 01010100 10011100
Codeword: 0x0E8A549C
Decoding: 0x0E8A549C
E1 : 0
E2 : 0
E4 : 0
E8 : 0
E16: 0
No error
-------- 01110100 01010101 01000011
Information Word: 0x745543 (CUt)
Decoding: 0x068A549C
E1 : 0
E2 : 0
E4 : 1
E8 : 1
E16: 1
Corrected bit: 28
-------- 01110100 01010101 01000011
Information Word: 0x745543 (CUt)
Decoding: 0x0F8A549C
E1 : 1
E2 : 0
E4 : 0
E8 : 1
E16: 1
Corrected bit: 25
-------- 01110100 01010101 01000011
Information Word: 0x745543 (CUt)
# : b@H weight 6 10101
Encoding: H @ b
0x 00 48 40 62
-------- 01001000 01000000 01100010
P1 : 1
P2 : 0
P4 : 1
P8 : 0
P16: 1
---01001 00001000 10000110 00011001
Codeword: 0x09088619
Decoding: 0x09088619
E1 : 0
E2 : 0
E4 : 0
E8 : 0
E16: 0
No error
-------- 01001000 01000000 01100010
Information Word: 0x484062 (b@H)
Decoding: 0x19088619
E1 : 1
E2 : 0
E4 : 1
E8 : 1
E16: 1
Corrected bit: 29
-------- 01001000 01000000 01100010
Information Word: 0x484062 (b@H)
Decoding: 0x09888619
E1 : 0
E2 : 0
E4 : 0
E8 : 1
E16: 1
Corrected bit: 24
-------- 01001000 01000000 01100010
Information Word: 0x484062 (b@H)
# : A@@ weight 4 00000
Encoding: @ @ A
0x 00 40 40 41
-------- 01000000 01000000 01000001
P1 : 0
P2 : 0
P4 : 0
P8 : 0
P16: 0
---01000 00001000 00000100 00000100
Codeword: 0x08080404
Decoding: 0x08080404
E1 : 0
E2 : 0
E4 : 0
E8 : 0
E16: 0
No error
-------- 01000000 01000000 01000001
Information Word: 0x404041 (A@@)
Decoding: 0x08000404
E1 : 0
E2 : 0
E4 : 1
E8 : 0
E16: 1
Corrected bit: 20
-------- 01000000 01000000 01000001
Information Word: 0x404041 (A@@)
Decoding: 0x08088404
E1 : 0
E2 : 0
E4 : 0
E8 : 0
E16: 1
Corrected bit: 16
-------- 01000000 01000000 01000001
Information Word: 0x404041 (A@@)
# : |?~ weight 17 11111
Encoding: } ? |
0x 00 7d 3f 7c
-------- 01111101 00111111 01111100
P1 : 1
P2 : 1
P4 : 1
P8 : 1
P16: 1
---01111 10100111 11110111 11101011
Codeword: 0x0FA7F7EB
Decoding: 0x0FA7F7EB
E1 : 0
E2 : 0
E4 : 0
E8 : 0
E16: 0
No error
-------- 01111101 00111111 01111100
Information Word: 0x7D3F7C (|?})
Decoding: 0x0FA7F3EB
E1 : 1
E2 : 1
E4 : 0
E8 : 1
E16: 0
Corrected bit: 11
-------- 01111101 00111111 01111100
Information Word: 0x7D3F7C (|?})
Decoding: 0x0FA7FFEB
E1 : 0
E2 : 0
E4 : 1
E8 : 1
E16: 0
Corrected bit: 12
-------- 01111101 00111111 01111100
Information Word: 0x7D3F7C (|?})
# : ~_ weight 16 00000
Encoding: _ ~ 
0x 00 5f 7e 5c
-------- 01011111 01111110 01011100
P1 : 0
P2 : 0
P4 : 0
P8 : 0
P16: 0
---01011 11101111 01100101 01100000
Codeword: 0x0BEF6560
Decoding: 0x0BEF6560
E1 : 0
E2 : 0
E4 : 0
E8 : 0
E16: 0
No error
-------- 01011111 01111110 01011100
Information Word: 0x5F7E5C (~_)
Decoding: 0x0BEF6561
E1 : 1
E2 : 0
E4 : 0
E8 : 0
E16: 0
Corrected bit: 1
-------- 01011111 01111110 01011100
Information Word: 0x5F7E5C (~_)
Decoding: 0x0BEF6562
E1 : 0
E2 : 1
E4 : 0
E8 : 0
E16: 0
Corrected bit: 2
-------- 01011111 01111110 01011100
Information Word: 0x5F7E5C (~_)
# : a decoding failure
Decoding: 0x0BEE2561
E1 : 1
E2 : 1
E4 : 1
E8 : 1
E16: 1
Decoding failure: 31
-------- 01011111 01110010 01011100
Information Word: 0x5F725C (r_)
Goodbye
You must then take these lower 24 bits (the information word) and shift them into a new integer
(the code word) at their proper positions. Since bits 1 and 2 of the code word are parity bits, bit 1
of the information word is bit 3 of the code word. Bit 4 of the code word is a parity bit, so bits 24
of the information word are bits 57 of the codeword, and so on as shown below: Once the
information bits have been copied to their appropriate location in the code word, you calculate
the value of the parity bits and set them accordingly. Continuing the same example, if the user
input is 'CUt', the template program has code to print the following two lines. You must write the
code to print the third line, which prints the information word as binary digits. Note that bit 24 is
the first digit that is printed and bit 1 is the last bit. Next you calculate the code word. The first
step is to shift the information bits into their final locations. The partially-filled code word is:
0111010001010P1010100P001P1PP where the Ps are parity bits. The value of each parity bit is
calculated so that the corresponding parity equation sums to zero. For example, here is the
calculation for parity bit 1 . Using the table on the previous page, make the sum of all the odd
bits equal to zero (mod2). 0+1+0+0+0+0+0+1+1+1+0+0+1+1+P=6+P1 So P1=0 so that
P1+6=0+6=6=0(mod2).
the expected value for P1 is 1 , but bit 1 in the code word (which holds the first parity bit) is 0 .
Since the parity bit in the code word does not match the expected value, set E1=1. Note P2 has
the expected value (since the equation for parity bit 2 does not include the bit in position 29).
Thus, E2 equals 0. Likewise, you find that E4, E8 and E16 are 1 because the expected value of
these parity bits does not match the bit found in the code word (or equivalently, bit number 29 is
included in all of these parity equations so the sum is odd instead of even). Now form the bit
error location by forming the binary number using the error location bits: E16 E8 E4 E2 E1 For
this example we have the binary number 11101 or decimal 29. This confirms that the error was
in bit location 29 , and you correct the value of bit 29 . The template program prints the code
word in hex. You add code to find the error location bits. Print the five error location bits and
convert them to an integer. The template program has code to print the integer error location.
You correct the code word, if necessary, and then print the information word in binary. Code is
provided that will print the information word in hex and display the information as characters if
possible. Note that if the bit error location is greater than 29 , then there was a decoding failure,
and the code word cannot be corrected. This can only happen if there is more than one bit in
error. Our program assumes that no more than one bit error occurs. Notes 1. This program can be
written many different ways, including using string functions to create an array of bits instead of
an integer of bits. Your program, however, must use bit manipulations (bitwise operations; no
string functions or arrays allowed!) on the given integers to receive credit. In addition, you
cannot use arrays to store the value of the bits. Code that does not use bitwise operations will not
be accepted.
Examples for MP2 CUt weight 1100110 enc CUt dec e8a549c dec 68a549c dec f8a549c enc
b@H b@H weight 610101 dec 9088619 dec 19088619 dec 9888619 enc A@@ dec 8080404 dec
8000404 dec 8088404 enc |?} dec fa7f7eb dec fa7f3eb dec fa7ffeb enc  dec bef 6560 dec
bef6561 dec bef6562 dec bee2561 a decoding failure quit
Count the number of red bits that are equal to one. There are 6 , so parity bit 2 is zero. That is,
P2=0. Now for P4. For parity bit 4 , we see that among the red bits, 5 of them are ones. So P4 =1
to make the parity even. Now for P8. So P8=1. And for P16,
222229876501110222221114321098710001010111111165432109P101010087654321P001P1P
P Then P16 =0. So the five parity bits P1, P2, P4, P8, and P16 are: 0,0,1,1, and 0 . The final code
word with the parity pits inserted is: ir The template program has code to print the ASCII letters
and the information word as hexadecimal digits. You must add code to print the information
word in binary with the most significant bits and bytes shown first. Next you must print the value
of each of the five parity bits. Lastly, you must print the binary values of the code word. The
program prints the hex values of the code word. Decoding The decoding operation inverts the
above steps. The decoding function accepts the 29-bit code word that is input by the keyboard.
You write code to re-calculate the value of the parity bits. Compare your calculation of your
expected parity bit value to the value in the code word, and if the values do not match then set an
error bit. Continuing the example above, if bit 29 of the code word is incorrect (i.e., 1 instead of
0 ), then the received code word is 01E8A549C. When you re-calculate the parity bits you find
that
The goal of this machine problem is to learn to program with bitwise operations. In this lab, you
write functions that perform bitwise operations on data in order to implement an error correcting
code. With faster bit rates and greater interference, error control coding is becoming increasingly
important in communications. Error detection coding can be used to detect whether or not bits
are (probably) in error, and error correction coding can be implemented to correct bits which are
(probably) in error. You are provided with a template program that prompts the user to enter
either a command to encode three ASCII characters, decode up to 8 hexadecimal digits, or exit.
Using the template, add functions to encode or decode the input. A template is provided and you
must use the organization provided. Encoding Three characters are entered as input, and your
program constructs a binary code word from the three characters. The codeword will be built
using a (29,24) Hamming code. That is, this code takes 24 bits of information and adds five
additional parity bits to give a 29 -bit code word. If we include our encoding algorithm in a
communications system, this code word allows the system to determine if the information that is
transmitted is received correctly as long as no more than one bit gets corrupted. Thus it is called
a single bit-error correcting code. The parity bits will be in bit positions 1,2,4,8, and 16 of the
code word. A parity bit is set such that the sum of the bits selected for a parity equation is equal
to zero (mod2) : The bits in the codeword that are included in a particular parity bit as shown in
the table to the right. That is, Bit 1 will be set to 0 if bits 3,5,7,9,11,13, 15,17,19,21,23,25,27, and
29 sum to an even number, and Bit 1 will be set to a 1 if they sum to odd number. The non-parity
(i.e., information) bits will simply be the values they were in the original 24 bits, only shifted to
their new position. To generate the information bits, the user inputs three characters. For
example, if the input is a C as the first character, U as the second, and t as the third, you will
construct the following 32 bit integer as follows. Since C=043,U=055, and t=074 your
information word (integer) should be 000745543 or
oid decode(unsigned int codeword) // you must determine these values: unsigned int info_word
=0; unsigned char first_letter =042; unsigned char second_letter =061; unsigned char third_letter
=064; int bit_error_location =21; // dummy variable int i=1; printf("Decoding: 0%.8Xn,
codeword); // // ADD your code here to fix a bit error if one exists // and determine the three
characters // // print the error location bits, one bit per line. Do not change // the format, but you
must change the dummy variable i // to match your design printf("E1 : %d n", i); printf("E2 :
%d n,i); printf("E4 : %d n,i); printf("E8 : %d n,i); printf("E16: %d n", i); // here is the
required format for the prints. Do not // change the format but update the variables to match //
your design if (bit_error_location == 0) printf(" No error n); else if (bit_error_location >0&&
bit_error_location <=29 ) { printf(" Corrected bit: %d n ", bit_error_location); } else printf("
Decoding failure: %d n, bit_error_location); // you must print the info_word in binary format //
print the information word in hex: printf(" Information Word: 0%.6X, info_word); // You must
convert the info_word into three characters for printing // only print information word as letters if
7-bit printable ASCII // otherwise print a space for non-printable information bits if ((first_letter
&080)==0 && isprint(first_letter)) printf(" (%c", first_letter); else printf(" ( "); if (
(second_letter &080)==0 && isprint(second_letter)) printf("%c", second_letter); else printf("
"); if ((third_letter &080)==0 && isprint(third_letter)) printf ("%C)n", third_letter); else
printf(")n"); printf("n");
/* encode: calculates parity bits and prints codeword * input: three ASCII characters *
assumptions: input is valid * Example: if input letters are is ' C ', ' U ', and ' t ' * the final print
must be: * ---01110100010100101010010011100 * Codeword: 0x0E8A549C / void
encode(unsigned char first_letter, unsigned char second_letter, unsigned char third_letter) { //
you must construct the codeword unsigned int codeword =0; int i=1;// dummy variable
printf("%9s%9c%9c%9c ", "Encoding:", third_letter, second_letter, first_letter) printf("
0x00%9%9%9xn", third_letter, second_letter, first_letter); // // ADD your code here // // print
the information word in binary form with spaces // print the parity bits, one bit per line. Do not
change // the format, but you must change the dummy variable i // to match your design
printf("P1 : %dn", i); printf("P2 : %d n", i); printf("P4 : %d n",i); printf("P8 : %d n",i);
printf("P16: %d n", i); // print the codeword bits in binary form with spaces // print the
codeword in hex format printf(" Codeword: 0x%.8Xn", codeword); printf("n"); } /* decode:
checks parity bits and prints information characters * input: A 29-bit codeword * assumptions:
the codeword has either no or only one error. the information characters may not be printable *
FYI: when a codeword has more than one error the decoding algorithm * may generate incorrect
information bits. In a practical system * inforamtion is grouped into multiple codewords and a
final CRC * code verifies if all codewords are correct. We will not * implement all of the details
of the system in this project. * Example: if the codeword is 0x0E8A549C * the final print must
be: * No error * ------- 011101000101010101000011 * Information Word: 0745543 (CUt) *
Example with one error in codeword bit 21: 0x0E9A549C * Notice the 8 in the previous example
has been changed to a 9 * the final print must be: * Corrected bit: 21 * --------
011101000101010101000011 * Information Word: 0745543 (CUt)
#include #include #include #include #define MAXLINE 100 // function prototypes void
encode(unsigned char first_letter, unsigned char second_letter, unsigned char third_letter); void
decode(unsigned int codeword); int main() { char line [MAXLINE]; char command
[MAXLINE] ; char inputcs [MAXLINE] ; int items; int i, invalid; unsigned int codeword;
printf("nMP2: encoding and decoding (29, 24) Hamming code. n); printf("Commands: ntenc
3-letters n tdec 8 -hex-digits n tquit n ") ; // each call to fgets, collects one line of input and
stores in line while (fgets (line, MAXLINE, stdin) != NULL) { items = sscanf(line, "%s%s",
command, inputcs); if (items == 1&&strcmp( command, "quit") == 0 ) { break; } else if (items
==2&&strcmp( command, "enc") ==0){ // encoding if (strlen(inputcs) != 3 || !isprint(inputcs[0])
|| !isprint(inputcs [1]) || !isprint(inputcs[2])) { printf("Invalid input to encoder: %sn", inputcs);
} else { encode(inputcs [0], inputcs[1], inputcs[2]); } } else if (items ==2 && strcmp
(command, "dec") ==0 ) { // decoding: convert hex digits to integer items = sscanf(inputcs,
"%x", &codeword); if (items !=1 strlen(inputcs) > 8) { printf("Invalid input to decoder: %sn",
inputcs); } else { // verify all digits are hex characters because // scanf does not reject invalid
letters for ( i=0, invalid =0;i

More Related Content

Similar to C code for encoding and decoding (29,24) Hamming code

Number systems and conversions
Number systems and conversionsNumber systems and conversions
Number systems and conversionsSusantha Herath
 
chapter one && two.pdf
chapter one && two.pdfchapter one && two.pdf
chapter one && two.pdfmiftah88
 
dtei-180910104911-converted.pptx
dtei-180910104911-converted.pptxdtei-180910104911-converted.pptx
dtei-180910104911-converted.pptxdeepaMS4
 
Presentation of ICT.ppt.pptx
Presentation of ICT.ppt.pptxPresentation of ICT.ppt.pptx
Presentation of ICT.ppt.pptxMinahilUmar1
 
IRJET- FPGA Implementation of Orthogonal Codes for Efficient Digital Communic...
IRJET- FPGA Implementation of Orthogonal Codes for Efficient Digital Communic...IRJET- FPGA Implementation of Orthogonal Codes for Efficient Digital Communic...
IRJET- FPGA Implementation of Orthogonal Codes for Efficient Digital Communic...IRJET Journal
 
Programming with 8085.pptx
Programming with 8085.pptxProgramming with 8085.pptx
Programming with 8085.pptxSachinKupade
 
Symbology upc
Symbology upcSymbology upc
Symbology upccri fan
 
computer architecture
computer architecture computer architecture
computer architecture Dr.Umadevi V
 
Data representation
Data representationData representation
Data representationManish Kumar
 
error handling codes
error handling codeserror handling codes
error handling codesAparnaLal2
 
Number system computer fundamental
 Number  system computer fundamental  Number  system computer fundamental
Number system computer fundamental Aman anand kumar
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
Computer archi&mp
Computer archi&mpComputer archi&mp
Computer archi&mpMSc CST
 
Gsp 215 Future Our Mission/newtonhelp.com
Gsp 215 Future Our Mission/newtonhelp.comGsp 215 Future Our Mission/newtonhelp.com
Gsp 215 Future Our Mission/newtonhelp.comamaranthbeg8
 

Similar to C code for encoding and decoding (29,24) Hamming code (20)

Number systems and conversions
Number systems and conversionsNumber systems and conversions
Number systems and conversions
 
chapter one && two.pdf
chapter one && two.pdfchapter one && two.pdf
chapter one && two.pdf
 
dtei-180910104911-converted.pptx
dtei-180910104911-converted.pptxdtei-180910104911-converted.pptx
dtei-180910104911-converted.pptx
 
Chapter 1: Binary System
 Chapter 1: Binary System Chapter 1: Binary System
Chapter 1: Binary System
 
DCF QNA edited
DCF QNA editedDCF QNA edited
DCF QNA edited
 
Presentation of ICT.ppt.pptx
Presentation of ICT.ppt.pptxPresentation of ICT.ppt.pptx
Presentation of ICT.ppt.pptx
 
IRJET- FPGA Implementation of Orthogonal Codes for Efficient Digital Communic...
IRJET- FPGA Implementation of Orthogonal Codes for Efficient Digital Communic...IRJET- FPGA Implementation of Orthogonal Codes for Efficient Digital Communic...
IRJET- FPGA Implementation of Orthogonal Codes for Efficient Digital Communic...
 
Programming with 8085.pptx
Programming with 8085.pptxProgramming with 8085.pptx
Programming with 8085.pptx
 
Symbology upc
Symbology upcSymbology upc
Symbology upc
 
9123497.ppt
9123497.ppt9123497.ppt
9123497.ppt
 
computer architecture
computer architecture computer architecture
computer architecture
 
Data representation
Data representationData representation
Data representation
 
Mcs 012 soved assignment 2015-16
Mcs 012 soved assignment 2015-16Mcs 012 soved assignment 2015-16
Mcs 012 soved assignment 2015-16
 
error handling codes
error handling codeserror handling codes
error handling codes
 
Number system computer fundamental
 Number  system computer fundamental  Number  system computer fundamental
Number system computer fundamental
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Intro to assembly language
Intro to assembly languageIntro to assembly language
Intro to assembly language
 
Computer archi&mp
Computer archi&mpComputer archi&mp
Computer archi&mp
 
Number system
Number systemNumber system
Number system
 
Gsp 215 Future Our Mission/newtonhelp.com
Gsp 215 Future Our Mission/newtonhelp.comGsp 215 Future Our Mission/newtonhelp.com
Gsp 215 Future Our Mission/newtonhelp.com
 

More from sales223546

XML, XSDCreate an XML file that satisfies the following schema..pdf
XML, XSDCreate an XML file that satisfies the following schema..pdfXML, XSDCreate an XML file that satisfies the following schema..pdf
XML, XSDCreate an XML file that satisfies the following schema..pdfsales223546
 
Write ItemList.h and ItemList.cItemList is used to store a list .pdf
Write ItemList.h and ItemList.cItemList is used to store a list .pdfWrite ItemList.h and ItemList.cItemList is used to store a list .pdf
Write ItemList.h and ItemList.cItemList is used to store a list .pdfsales223546
 
Write a python script that will perform these operations procedurall.pdf
Write a python script that will perform these operations procedurall.pdfWrite a python script that will perform these operations procedurall.pdf
Write a python script that will perform these operations procedurall.pdfsales223546
 
Write a Python program that allows users to keep track of soccer pla.pdf
Write a Python program that allows users to keep track of soccer pla.pdfWrite a Python program that allows users to keep track of soccer pla.pdf
Write a Python program that allows users to keep track of soccer pla.pdfsales223546
 
Will upvote asapPlease help my code gives me incorrect val.pdf
Will upvote asapPlease help my code gives me incorrect val.pdfWill upvote asapPlease help my code gives me incorrect val.pdf
Will upvote asapPlease help my code gives me incorrect val.pdfsales223546
 
Who started the apple organization What were they doing at the time.pdf
Who started the apple organization What were they doing at the time.pdfWho started the apple organization What were they doing at the time.pdf
Who started the apple organization What were they doing at the time.pdfsales223546
 
Which supervision conditions are pertinent to these sex offenders.pdf
Which supervision conditions are pertinent to these sex offenders.pdfWhich supervision conditions are pertinent to these sex offenders.pdf
Which supervision conditions are pertinent to these sex offenders.pdfsales223546
 
Which of the following is a form of market participation A. The South.pdf
Which of the following is a form of market participation A. The South.pdfWhich of the following is a form of market participation A. The South.pdf
Which of the following is a form of market participation A. The South.pdfsales223546
 
Which of the following is a form of market participation A) the.pdf
Which of the following is a form of market participation A) the.pdfWhich of the following is a form of market participation A) the.pdf
Which of the following is a form of market participation A) the.pdfsales223546
 
Week 6 Class Assessment Implementation Plan for an HRD Learning Int.pdf
Week 6 Class Assessment Implementation Plan for an HRD Learning Int.pdfWeek 6 Class Assessment Implementation Plan for an HRD Learning Int.pdf
Week 6 Class Assessment Implementation Plan for an HRD Learning Int.pdfsales223546
 
Water restored in parts of Tshwane after two-day outagePretoria - .pdf
Water restored in parts of Tshwane after two-day outagePretoria - .pdfWater restored in parts of Tshwane after two-day outagePretoria - .pdf
Water restored in parts of Tshwane after two-day outagePretoria - .pdfsales223546
 
Venture Investors Bet AI Can Improve Supply-Chain ManagementLogist.pdf
Venture Investors Bet AI Can Improve Supply-Chain ManagementLogist.pdfVenture Investors Bet AI Can Improve Supply-Chain ManagementLogist.pdf
Venture Investors Bet AI Can Improve Supply-Chain ManagementLogist.pdfsales223546
 
using draw.io You are tasked with designing a database for a Movie.pdf
using draw.io You are tasked with designing a database for a Movie.pdfusing draw.io You are tasked with designing a database for a Movie.pdf
using draw.io You are tasked with designing a database for a Movie.pdfsales223546
 
Using jQuery, set up functionality to capture the forms input eleme.pdf
Using jQuery, set up functionality to capture the forms input eleme.pdfUsing jQuery, set up functionality to capture the forms input eleme.pdf
Using jQuery, set up functionality to capture the forms input eleme.pdfsales223546
 
using draw.io Task 3 Design an ER Diagram for a Library Management .pdf
using draw.io Task 3 Design an ER Diagram for a Library Management .pdfusing draw.io Task 3 Design an ER Diagram for a Library Management .pdf
using draw.io Task 3 Design an ER Diagram for a Library Management .pdfsales223546
 
using draw.io Task 2 Design an ER Diagram for a Music Streaming.pdf
using draw.io Task 2 Design an ER Diagram for a Music Streaming.pdfusing draw.io Task 2 Design an ER Diagram for a Music Streaming.pdf
using draw.io Task 2 Design an ER Diagram for a Music Streaming.pdfsales223546
 
UnixLinux 1. Use screen shots or video to demonstrate the before an.pdf
UnixLinux 1. Use screen shots or video to demonstrate the before an.pdfUnixLinux 1. Use screen shots or video to demonstrate the before an.pdf
UnixLinux 1. Use screen shots or video to demonstrate the before an.pdfsales223546
 
use python Problem 2. Selection Sort In this problem you will implem.pdf
use python Problem 2. Selection Sort In this problem you will implem.pdfuse python Problem 2. Selection Sort In this problem you will implem.pdf
use python Problem 2. Selection Sort In this problem you will implem.pdfsales223546
 
You are task to add a yawning detection to the programme below;i.pdf
You are task to add a yawning detection to the programme below;i.pdfYou are task to add a yawning detection to the programme below;i.pdf
You are task to add a yawning detection to the programme below;i.pdfsales223546
 

More from sales223546 (19)

XML, XSDCreate an XML file that satisfies the following schema..pdf
XML, XSDCreate an XML file that satisfies the following schema..pdfXML, XSDCreate an XML file that satisfies the following schema..pdf
XML, XSDCreate an XML file that satisfies the following schema..pdf
 
Write ItemList.h and ItemList.cItemList is used to store a list .pdf
Write ItemList.h and ItemList.cItemList is used to store a list .pdfWrite ItemList.h and ItemList.cItemList is used to store a list .pdf
Write ItemList.h and ItemList.cItemList is used to store a list .pdf
 
Write a python script that will perform these operations procedurall.pdf
Write a python script that will perform these operations procedurall.pdfWrite a python script that will perform these operations procedurall.pdf
Write a python script that will perform these operations procedurall.pdf
 
Write a Python program that allows users to keep track of soccer pla.pdf
Write a Python program that allows users to keep track of soccer pla.pdfWrite a Python program that allows users to keep track of soccer pla.pdf
Write a Python program that allows users to keep track of soccer pla.pdf
 
Will upvote asapPlease help my code gives me incorrect val.pdf
Will upvote asapPlease help my code gives me incorrect val.pdfWill upvote asapPlease help my code gives me incorrect val.pdf
Will upvote asapPlease help my code gives me incorrect val.pdf
 
Who started the apple organization What were they doing at the time.pdf
Who started the apple organization What were they doing at the time.pdfWho started the apple organization What were they doing at the time.pdf
Who started the apple organization What were they doing at the time.pdf
 
Which supervision conditions are pertinent to these sex offenders.pdf
Which supervision conditions are pertinent to these sex offenders.pdfWhich supervision conditions are pertinent to these sex offenders.pdf
Which supervision conditions are pertinent to these sex offenders.pdf
 
Which of the following is a form of market participation A. The South.pdf
Which of the following is a form of market participation A. The South.pdfWhich of the following is a form of market participation A. The South.pdf
Which of the following is a form of market participation A. The South.pdf
 
Which of the following is a form of market participation A) the.pdf
Which of the following is a form of market participation A) the.pdfWhich of the following is a form of market participation A) the.pdf
Which of the following is a form of market participation A) the.pdf
 
Week 6 Class Assessment Implementation Plan for an HRD Learning Int.pdf
Week 6 Class Assessment Implementation Plan for an HRD Learning Int.pdfWeek 6 Class Assessment Implementation Plan for an HRD Learning Int.pdf
Week 6 Class Assessment Implementation Plan for an HRD Learning Int.pdf
 
Water restored in parts of Tshwane after two-day outagePretoria - .pdf
Water restored in parts of Tshwane after two-day outagePretoria - .pdfWater restored in parts of Tshwane after two-day outagePretoria - .pdf
Water restored in parts of Tshwane after two-day outagePretoria - .pdf
 
Venture Investors Bet AI Can Improve Supply-Chain ManagementLogist.pdf
Venture Investors Bet AI Can Improve Supply-Chain ManagementLogist.pdfVenture Investors Bet AI Can Improve Supply-Chain ManagementLogist.pdf
Venture Investors Bet AI Can Improve Supply-Chain ManagementLogist.pdf
 
using draw.io You are tasked with designing a database for a Movie.pdf
using draw.io You are tasked with designing a database for a Movie.pdfusing draw.io You are tasked with designing a database for a Movie.pdf
using draw.io You are tasked with designing a database for a Movie.pdf
 
Using jQuery, set up functionality to capture the forms input eleme.pdf
Using jQuery, set up functionality to capture the forms input eleme.pdfUsing jQuery, set up functionality to capture the forms input eleme.pdf
Using jQuery, set up functionality to capture the forms input eleme.pdf
 
using draw.io Task 3 Design an ER Diagram for a Library Management .pdf
using draw.io Task 3 Design an ER Diagram for a Library Management .pdfusing draw.io Task 3 Design an ER Diagram for a Library Management .pdf
using draw.io Task 3 Design an ER Diagram for a Library Management .pdf
 
using draw.io Task 2 Design an ER Diagram for a Music Streaming.pdf
using draw.io Task 2 Design an ER Diagram for a Music Streaming.pdfusing draw.io Task 2 Design an ER Diagram for a Music Streaming.pdf
using draw.io Task 2 Design an ER Diagram for a Music Streaming.pdf
 
UnixLinux 1. Use screen shots or video to demonstrate the before an.pdf
UnixLinux 1. Use screen shots or video to demonstrate the before an.pdfUnixLinux 1. Use screen shots or video to demonstrate the before an.pdf
UnixLinux 1. Use screen shots or video to demonstrate the before an.pdf
 
use python Problem 2. Selection Sort In this problem you will implem.pdf
use python Problem 2. Selection Sort In this problem you will implem.pdfuse python Problem 2. Selection Sort In this problem you will implem.pdf
use python Problem 2. Selection Sort In this problem you will implem.pdf
 
You are task to add a yawning detection to the programme below;i.pdf
You are task to add a yawning detection to the programme below;i.pdfYou are task to add a yawning detection to the programme below;i.pdf
You are task to add a yawning detection to the programme below;i.pdf
 

Recently uploaded

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 

Recently uploaded (20)

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 

C code for encoding and decoding (29,24) Hamming code

  • 1. Write the code in C, here is the template provided: The input used is: The output should look exactly like this: MP2: encoding and decoding (29, 24) Hamming code. Commands: enc 3-letters dec 8-hex-digits quit # :Examples for MP2 # : CUt weight 11 00110 Encoding: t U C 0x 00 74 55 43 -------- 01110100 01010101 01000011 P1 : 0 P2 : 0 P4 : 1 P8 : 1 P16: 0 ---01110 10001010 01010100 10011100 Codeword: 0x0E8A549C Decoding: 0x0E8A549C E1 : 0 E2 : 0 E4 : 0 E8 : 0 E16: 0 No error -------- 01110100 01010101 01000011 Information Word: 0x745543 (CUt) Decoding: 0x068A549C E1 : 0 E2 : 0 E4 : 1 E8 : 1 E16: 1
  • 2. Corrected bit: 28 -------- 01110100 01010101 01000011 Information Word: 0x745543 (CUt) Decoding: 0x0F8A549C E1 : 1 E2 : 0 E4 : 0 E8 : 1 E16: 1 Corrected bit: 25 -------- 01110100 01010101 01000011 Information Word: 0x745543 (CUt) # : b@H weight 6 10101 Encoding: H @ b 0x 00 48 40 62 -------- 01001000 01000000 01100010 P1 : 1 P2 : 0 P4 : 1 P8 : 0 P16: 1 ---01001 00001000 10000110 00011001 Codeword: 0x09088619 Decoding: 0x09088619 E1 : 0 E2 : 0 E4 : 0 E8 : 0 E16: 0 No error -------- 01001000 01000000 01100010 Information Word: 0x484062 (b@H) Decoding: 0x19088619 E1 : 1 E2 : 0 E4 : 1
  • 3. E8 : 1 E16: 1 Corrected bit: 29 -------- 01001000 01000000 01100010 Information Word: 0x484062 (b@H) Decoding: 0x09888619 E1 : 0 E2 : 0 E4 : 0 E8 : 1 E16: 1 Corrected bit: 24 -------- 01001000 01000000 01100010 Information Word: 0x484062 (b@H) # : A@@ weight 4 00000 Encoding: @ @ A 0x 00 40 40 41 -------- 01000000 01000000 01000001 P1 : 0 P2 : 0 P4 : 0 P8 : 0 P16: 0 ---01000 00001000 00000100 00000100 Codeword: 0x08080404 Decoding: 0x08080404 E1 : 0 E2 : 0 E4 : 0 E8 : 0 E16: 0 No error -------- 01000000 01000000 01000001 Information Word: 0x404041 (A@@) Decoding: 0x08000404 E1 : 0
  • 4. E2 : 0 E4 : 1 E8 : 0 E16: 1 Corrected bit: 20 -------- 01000000 01000000 01000001 Information Word: 0x404041 (A@@) Decoding: 0x08088404 E1 : 0 E2 : 0 E4 : 0 E8 : 0 E16: 1 Corrected bit: 16 -------- 01000000 01000000 01000001 Information Word: 0x404041 (A@@) # : |?~ weight 17 11111 Encoding: } ? | 0x 00 7d 3f 7c -------- 01111101 00111111 01111100 P1 : 1 P2 : 1 P4 : 1 P8 : 1 P16: 1 ---01111 10100111 11110111 11101011 Codeword: 0x0FA7F7EB Decoding: 0x0FA7F7EB E1 : 0 E2 : 0 E4 : 0 E8 : 0 E16: 0 No error -------- 01111101 00111111 01111100 Information Word: 0x7D3F7C (|?})
  • 5. Decoding: 0x0FA7F3EB E1 : 1 E2 : 1 E4 : 0 E8 : 1 E16: 0 Corrected bit: 11 -------- 01111101 00111111 01111100 Information Word: 0x7D3F7C (|?}) Decoding: 0x0FA7FFEB E1 : 0 E2 : 0 E4 : 1 E8 : 1 E16: 0 Corrected bit: 12 -------- 01111101 00111111 01111100 Information Word: 0x7D3F7C (|?}) # : ~_ weight 16 00000 Encoding: _ ~ 0x 00 5f 7e 5c -------- 01011111 01111110 01011100 P1 : 0 P2 : 0 P4 : 0 P8 : 0 P16: 0 ---01011 11101111 01100101 01100000 Codeword: 0x0BEF6560 Decoding: 0x0BEF6560 E1 : 0 E2 : 0 E4 : 0 E8 : 0 E16: 0 No error
  • 6. -------- 01011111 01111110 01011100 Information Word: 0x5F7E5C (~_) Decoding: 0x0BEF6561 E1 : 1 E2 : 0 E4 : 0 E8 : 0 E16: 0 Corrected bit: 1 -------- 01011111 01111110 01011100 Information Word: 0x5F7E5C (~_) Decoding: 0x0BEF6562 E1 : 0 E2 : 1 E4 : 0 E8 : 0 E16: 0 Corrected bit: 2 -------- 01011111 01111110 01011100 Information Word: 0x5F7E5C (~_) # : a decoding failure Decoding: 0x0BEE2561 E1 : 1 E2 : 1 E4 : 1 E8 : 1 E16: 1 Decoding failure: 31 -------- 01011111 01110010 01011100 Information Word: 0x5F725C (r_) Goodbye You must then take these lower 24 bits (the information word) and shift them into a new integer (the code word) at their proper positions. Since bits 1 and 2 of the code word are parity bits, bit 1 of the information word is bit 3 of the code word. Bit 4 of the code word is a parity bit, so bits 24
  • 7. of the information word are bits 57 of the codeword, and so on as shown below: Once the information bits have been copied to their appropriate location in the code word, you calculate the value of the parity bits and set them accordingly. Continuing the same example, if the user input is 'CUt', the template program has code to print the following two lines. You must write the code to print the third line, which prints the information word as binary digits. Note that bit 24 is the first digit that is printed and bit 1 is the last bit. Next you calculate the code word. The first step is to shift the information bits into their final locations. The partially-filled code word is: 0111010001010P1010100P001P1PP where the Ps are parity bits. The value of each parity bit is calculated so that the corresponding parity equation sums to zero. For example, here is the calculation for parity bit 1 . Using the table on the previous page, make the sum of all the odd bits equal to zero (mod2). 0+1+0+0+0+0+0+1+1+1+0+0+1+1+P=6+P1 So P1=0 so that P1+6=0+6=6=0(mod2). the expected value for P1 is 1 , but bit 1 in the code word (which holds the first parity bit) is 0 . Since the parity bit in the code word does not match the expected value, set E1=1. Note P2 has the expected value (since the equation for parity bit 2 does not include the bit in position 29). Thus, E2 equals 0. Likewise, you find that E4, E8 and E16 are 1 because the expected value of these parity bits does not match the bit found in the code word (or equivalently, bit number 29 is included in all of these parity equations so the sum is odd instead of even). Now form the bit error location by forming the binary number using the error location bits: E16 E8 E4 E2 E1 For this example we have the binary number 11101 or decimal 29. This confirms that the error was in bit location 29 , and you correct the value of bit 29 . The template program prints the code word in hex. You add code to find the error location bits. Print the five error location bits and convert them to an integer. The template program has code to print the integer error location.
  • 8. You correct the code word, if necessary, and then print the information word in binary. Code is provided that will print the information word in hex and display the information as characters if possible. Note that if the bit error location is greater than 29 , then there was a decoding failure, and the code word cannot be corrected. This can only happen if there is more than one bit in error. Our program assumes that no more than one bit error occurs. Notes 1. This program can be written many different ways, including using string functions to create an array of bits instead of an integer of bits. Your program, however, must use bit manipulations (bitwise operations; no string functions or arrays allowed!) on the given integers to receive credit. In addition, you cannot use arrays to store the value of the bits. Code that does not use bitwise operations will not be accepted. Examples for MP2 CUt weight 1100110 enc CUt dec e8a549c dec 68a549c dec f8a549c enc b@H b@H weight 610101 dec 9088619 dec 19088619 dec 9888619 enc A@@ dec 8080404 dec 8000404 dec 8088404 enc |?} dec fa7f7eb dec fa7f3eb dec fa7ffeb enc dec bef 6560 dec bef6561 dec bef6562 dec bee2561 a decoding failure quit Count the number of red bits that are equal to one. There are 6 , so parity bit 2 is zero. That is, P2=0. Now for P4. For parity bit 4 , we see that among the red bits, 5 of them are ones. So P4 =1 to make the parity even. Now for P8. So P8=1. And for P16, 222229876501110222221114321098710001010111111165432109P101010087654321P001P1P P Then P16 =0. So the five parity bits P1, P2, P4, P8, and P16 are: 0,0,1,1, and 0 . The final code word with the parity pits inserted is: ir The template program has code to print the ASCII letters and the information word as hexadecimal digits. You must add code to print the information word in binary with the most significant bits and bytes shown first. Next you must print the value of each of the five parity bits. Lastly, you must print the binary values of the code word. The program prints the hex values of the code word. Decoding The decoding operation inverts the above steps. The decoding function accepts the 29-bit code word that is input by the keyboard. You write code to re-calculate the value of the parity bits. Compare your calculation of your expected parity bit value to the value in the code word, and if the values do not match then set an error bit. Continuing the example above, if bit 29 of the code word is incorrect (i.e., 1 instead of 0 ), then the received code word is 01E8A549C. When you re-calculate the parity bits you find that The goal of this machine problem is to learn to program with bitwise operations. In this lab, you write functions that perform bitwise operations on data in order to implement an error correcting code. With faster bit rates and greater interference, error control coding is becoming increasingly
  • 9. important in communications. Error detection coding can be used to detect whether or not bits are (probably) in error, and error correction coding can be implemented to correct bits which are (probably) in error. You are provided with a template program that prompts the user to enter either a command to encode three ASCII characters, decode up to 8 hexadecimal digits, or exit. Using the template, add functions to encode or decode the input. A template is provided and you must use the organization provided. Encoding Three characters are entered as input, and your program constructs a binary code word from the three characters. The codeword will be built using a (29,24) Hamming code. That is, this code takes 24 bits of information and adds five additional parity bits to give a 29 -bit code word. If we include our encoding algorithm in a communications system, this code word allows the system to determine if the information that is transmitted is received correctly as long as no more than one bit gets corrupted. Thus it is called a single bit-error correcting code. The parity bits will be in bit positions 1,2,4,8, and 16 of the code word. A parity bit is set such that the sum of the bits selected for a parity equation is equal to zero (mod2) : The bits in the codeword that are included in a particular parity bit as shown in the table to the right. That is, Bit 1 will be set to 0 if bits 3,5,7,9,11,13, 15,17,19,21,23,25,27, and 29 sum to an even number, and Bit 1 will be set to a 1 if they sum to odd number. The non-parity (i.e., information) bits will simply be the values they were in the original 24 bits, only shifted to their new position. To generate the information bits, the user inputs three characters. For example, if the input is a C as the first character, U as the second, and t as the third, you will construct the following 32 bit integer as follows. Since C=043,U=055, and t=074 your information word (integer) should be 000745543 or oid decode(unsigned int codeword) // you must determine these values: unsigned int info_word =0; unsigned char first_letter =042; unsigned char second_letter =061; unsigned char third_letter =064; int bit_error_location =21; // dummy variable int i=1; printf("Decoding: 0%.8Xn, codeword); // // ADD your code here to fix a bit error if one exists // and determine the three characters // // print the error location bits, one bit per line. Do not change // the format, but you must change the dummy variable i // to match your design printf("E1 : %d n", i); printf("E2 : %d n,i); printf("E4 : %d n,i); printf("E8 : %d n,i); printf("E16: %d n", i); // here is the required format for the prints. Do not // change the format but update the variables to match // your design if (bit_error_location == 0) printf(" No error n); else if (bit_error_location >0&& bit_error_location <=29 ) { printf(" Corrected bit: %d n ", bit_error_location); } else printf(" Decoding failure: %d n, bit_error_location); // you must print the info_word in binary format // print the information word in hex: printf(" Information Word: 0%.6X, info_word); // You must convert the info_word into three characters for printing // only print information word as letters if 7-bit printable ASCII // otherwise print a space for non-printable information bits if ((first_letter
  • 10. &080)==0 && isprint(first_letter)) printf(" (%c", first_letter); else printf(" ( "); if ( (second_letter &080)==0 && isprint(second_letter)) printf("%c", second_letter); else printf(" "); if ((third_letter &080)==0 && isprint(third_letter)) printf ("%C)n", third_letter); else printf(")n"); printf("n"); /* encode: calculates parity bits and prints codeword * input: three ASCII characters * assumptions: input is valid * Example: if input letters are is ' C ', ' U ', and ' t ' * the final print must be: * ---01110100010100101010010011100 * Codeword: 0x0E8A549C / void encode(unsigned char first_letter, unsigned char second_letter, unsigned char third_letter) { // you must construct the codeword unsigned int codeword =0; int i=1;// dummy variable printf("%9s%9c%9c%9c ", "Encoding:", third_letter, second_letter, first_letter) printf(" 0x00%9%9%9xn", third_letter, second_letter, first_letter); // // ADD your code here // // print the information word in binary form with spaces // print the parity bits, one bit per line. Do not change // the format, but you must change the dummy variable i // to match your design printf("P1 : %dn", i); printf("P2 : %d n", i); printf("P4 : %d n",i); printf("P8 : %d n",i); printf("P16: %d n", i); // print the codeword bits in binary form with spaces // print the codeword in hex format printf(" Codeword: 0x%.8Xn", codeword); printf("n"); } /* decode: checks parity bits and prints information characters * input: A 29-bit codeword * assumptions: the codeword has either no or only one error. the information characters may not be printable * FYI: when a codeword has more than one error the decoding algorithm * may generate incorrect information bits. In a practical system * inforamtion is grouped into multiple codewords and a final CRC * code verifies if all codewords are correct. We will not * implement all of the details of the system in this project. * Example: if the codeword is 0x0E8A549C * the final print must be: * No error * ------- 011101000101010101000011 * Information Word: 0745543 (CUt) * Example with one error in codeword bit 21: 0x0E9A549C * Notice the 8 in the previous example has been changed to a 9 * the final print must be: * Corrected bit: 21 * -------- 011101000101010101000011 * Information Word: 0745543 (CUt) #include #include #include #include #define MAXLINE 100 // function prototypes void encode(unsigned char first_letter, unsigned char second_letter, unsigned char third_letter); void decode(unsigned int codeword); int main() { char line [MAXLINE]; char command [MAXLINE] ; char inputcs [MAXLINE] ; int items; int i, invalid; unsigned int codeword; printf("nMP2: encoding and decoding (29, 24) Hamming code. n); printf("Commands: ntenc 3-letters n tdec 8 -hex-digits n tquit n ") ; // each call to fgets, collects one line of input and stores in line while (fgets (line, MAXLINE, stdin) != NULL) { items = sscanf(line, "%s%s", command, inputcs); if (items == 1&&strcmp( command, "quit") == 0 ) { break; } else if (items
  • 11. ==2&&strcmp( command, "enc") ==0){ // encoding if (strlen(inputcs) != 3 || !isprint(inputcs[0]) || !isprint(inputcs [1]) || !isprint(inputcs[2])) { printf("Invalid input to encoder: %sn", inputcs); } else { encode(inputcs [0], inputcs[1], inputcs[2]); } } else if (items ==2 && strcmp (command, "dec") ==0 ) { // decoding: convert hex digits to integer items = sscanf(inputcs, "%x", &codeword); if (items !=1 strlen(inputcs) > 8) { printf("Invalid input to decoder: %sn", inputcs); } else { // verify all digits are hex characters because // scanf does not reject invalid letters for ( i=0, invalid =0;i