0% found this document useful (0 votes)
28 views6 pages

Checksum

The document explains checksum and Hamming code as error detection and correction mechanisms in data communication. It details the checksum process on sender and receiver sides, providing examples of calculations. Additionally, it describes Hamming code's functionality, including redundant bits, parity bits, and its ability to detect and correct single-bit errors, while also addressing burst errors.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views6 pages

Checksum

The document explains checksum and Hamming code as error detection and correction mechanisms in data communication. It details the checksum process on sender and receiver sides, providing examples of calculations. Additionally, it describes Hamming code's functionality, including redundant bits, parity bits, and its ability to detect and correct single-bit errors, while also addressing burst errors.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Checksum Program in C: Checksum is an error detection mechanism that

detects the error in the data/message in a data communication from sender to


receiver. It is only an error detection mechanism and hence cannot correct the
errors in the message bits.

It uses Checksum generator on the sender side and Checksum checker on the
receiver side to check the errors.
Example:
Number of messages transmitted: 2
Elements to calculate Checksum:
1011
1110
****SENDER SIDE****
SUM IS: 2121
CHECKSUM IS: 2122

****RECEIVER SIDE****
SUM IS: 2121
CHECKSUM IS: 0

Runtime Test Cases

Testcase 1: In this case, we enter “2” as the length of the string and “1011” and
“0111” as array elements to calculate the checksum.

ENTER SIZE OF THE STRING:2

ENTER THE ELEMENTS OF THE ARRAY TO CALCULATE CHECKSUM:

1011

0111

****SENDER SIDE****

SUM IS: 1122

CHECKSUM IS:1123

****RECEIVER SIDE****

SUM IS:1122
CHECKSUM IS:0

Testcase 2: In this case, we enter “4” as the length of the string and
“10110101”, “11000111”, “01101100” and “00001111” as array elements to
calculate the checksum.

ENTER SIZE OF THE STRING:4

ENTER THE ELEMENTS OF THE ARRAY TO CALCULATE CHECKSUM:

10110101

11000111

01101100

00001111

****SENDER SIDE****

SUM IS: 22212423

CHECKSUM IS:22212424

****RECEIVER SIDE****

SUM IS:22212423

CHECKSUM IS:0

Hamming Code Generation:

Hamming code is an error-correcting code used to ensure data accuracy during


transmission or storage. Hamming code detects and corrects the errors that can
occur when the data is moved or stored from the sender to the receiver. This
simple and effective method helps improve the reliability of communication
systems and digital storage. It adds extra bits to the original data, allowing the
system to detect and correct single-bit errors.

1. Error-correcting code
A code used in digital communications to detect and correct errors parallelly
that occur during data transmission.
2. Redundant bits
The extra bits added to a message to enable error detection and correction.
Hamming code uses redundancy to detect and correct errors in transmitted
messages
To calculate redundant bits, we can use the expression
2r>=d+r+1, here d = data bits and r = redundant bits

3. Position of redundant bits


The redundant bits are assigned to positions that coincide with the power of 2.
Ex, 2^p (where p=0,1,2,3…)

Redundant bits: r1, r2, r4


Data bits: d0, d1, d2, d3

4. Parity bit
An extra bit added to a message to check for errors. The number of 1s in the
message finds the parity bit's value.
Parity bits are of two types
 Odd parity: Here, the count of 1's should be odd
 Even Parity: Here, the count of 1's should be even

5. Single-bit error
An error that occurs when only one bit of a message is incorrect. Hamming
code can detect and correct single-bit errors.
6. Hamming distance
Hamming distance is the count of the number of bit positions in which two code
messages differ. Hamming distance is used to find the minimum number of
parity bits required for error detection and correction
7. Generator matrix
A matrix used to generate the parity bits for a Hamming code. The generator
matrix calculates the parity bits for a given code word.
8. Check matrix
A matrix used to check for errors in a Hamming code. The check matrix
calculates the syndrome for a given received message.
9. Burst error
An error that occurs when multiple bits in a message are incorrect. Hamming
code is not able to correct burst errors. It only detects them.
Examples of Hamming Code in Computer Networks
Generation of hamming Code
 Suppose we have a 4-bit message that we want to transmit: 111011. Now
we apply the above steps in this hamming code example.
 To calculate the parity bits, we use the formula,

2^r>=r+d+1 => 2^r>=r+6+1


=> 2^r>=r+7
Now by putting r=4, the above equation satisfies the condition.
 Thus we will use a Hamming code with four parity bits, which requires a
10-bit code word. We place the message bits in positions 3, 5, 6, 7, 9, and
10 of the code word and the parity bits in positions 1, 2, 4, and 8, as shown
below:

For even parity transmission


 For r1: bit positions 1,3,5,7,9. The positions are identified by selecting only
those bit indexes whose binary form includes a 1 in the least significant bit
position.

As the number of 1's at all bit positions corresponding to r1 is odd, the value of
r1=1
 Similarly, we calculate r2 with the help of a parity check. The positions are
identified by selecting only those bit indexes whose binary form includes a
1 in the 2nd index from the least significant bit. Thus the bit positions are 2,
3, 6, 7, and 10, and the corresponding value for r2=1, considering even
parity.

 Similarly, for r3: The positions are identified by selecting only those bit
indexes whose binary form includes a 1 in the 3rd index from the least
significant bit. Bit positions are 4, 5, 6, and 7 with the value of r4=0 to
satisfy even parity.

 For r4: The positions are identified by selecting only those bit indexes
whose binary form includes a 1 in the 4th index from the least significant
bit. Bit positions are 8, 9 and 10 with the value of r8=0 to satisfy even
parity.

 Now putting all the parity bit values in the message, we get the Hamming
code as 1110110011 for this hamming code example.

You might also like