0% found this document useful (0 votes)
157 views7 pages

Assignment No. 3: Title: Lab Assignment On Unit II: (Use C/C++)

The document describes an assignment to implement error detection and correction using Hamming codes or CRC. It provides details on Hamming codes and CRC including: - Hamming codes use parity bits to detect up to two-bit errors or correct one-bit errors. The placement of parity bits follows a specific algorithm using the binary representation of bit positions. - CRC generates a checksum by dividing the data bits by a predetermined polynomial. The remainder is sent along with the data and checked by the receiver. The assignment requires students to demonstrate Hamming codes or CRC with examples and capture network packets using Wireshark to analyze peer-to-peer communication.

Uploaded by

Darshan Derle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
157 views7 pages

Assignment No. 3: Title: Lab Assignment On Unit II: (Use C/C++)

The document describes an assignment to implement error detection and correction using Hamming codes or CRC. It provides details on Hamming codes and CRC including: - Hamming codes use parity bits to detect up to two-bit errors or correct one-bit errors. The placement of parity bits follows a specific algorithm using the binary representation of bit positions. - CRC generates a checksum by dividing the data bits by a predetermined polynomial. The remainder is sent along with the data and checked by the receiver. The assignment requires students to demonstrate Hamming codes or CRC with examples and capture network packets using Wireshark to analyze peer-to-peer communication.

Uploaded by

Darshan Derle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Assignment No.

Title: Lab Assignment on Unit II: (Use C/C++)

Write a program for error detection and correction for 7/8 bits ASCII codes using Hamming Codes
or CRC. Demonstrate the packets captured traces using Wireshark Packet Analyzer Tool for peer
to peer mode

Outcomes:
Demonstrate Hamming Codes and CRC with example.

Theory:
Hamming code
• Hamming codes are a family of linear error-correcting codes that generalize
the Hamming(7,4)-code
• Invented by Richard Hamming in 1950 Hamming codes can detect up to two-bit errors or
correct one-bit errors without detection of uncorrected errors.

General algorithm
• The following general algorithm generates a single-error correcting (SEC) code for any
number of bits.
• Number the bits starting from 1: bit 1, 2, 3, 4, 5, etc.
• Write the bit numbers in binary: 1, 10, 11, 100, 101, etc.
• All bit positions that are powers of two (have only one 1 bit in the binary form of their position)
are parity bits: 1, 2, 4, 8, etc. (1, 10, 100, 1000)
• All other bit positions, with two or more 1 bits in the binary form of their position, are data
bits.
• Each data bit is included in a unique set of 2 or more parity bits, as determined by the binary
form of its bit position.
• Each data bit is included in a unique set of 2 or more parity bits, as determined by the binary
form of its bit position.
• Parity bit 1 covers all bit positions which have the least significant bit set: bit 1 (the parity bit
itself), 3, 5, 7, 9, etc.
• Parity bit 2 covers all bit positions which have the second least significant bit set: bit 2 (the
parity bit itself), 3, 6, 7, 10, 11, etc.
• Parity bit 4 covers all bit positions which have the third least significant bit set: bits 4–7, 12–
15, 20–23, etc.
• Parity bit 8 covers all bit positions which have the fourth least significant bit set: bits 8–15,
24–31, 40–47, etc.
• In general each parity bit covers all bits where the bitwise AND of the parity position and the
bit position is non-zero.
Example Error detection

Error correction

Cyclic Redundancy Check: CRC

• Given a k-bit frame or message, the transmitter generates an n-bit sequence, known as a
frame check sequence (FCS), so that the resulting frame, consisting of (k+n) bits, is exactly
divisible by some predetermined number.
• The receiver then divides the incoming frame by the same number and, if there is no
remainder, assumes that there was no error.
Example:

Conclusion: Hence we have learned the techniques for error detection and correction

Output:
FAQ

1. Explain error correction and detection at the data link layer.

➔ Error Detection Techniques


There are three main techniques for detecting errors: Parity Check, Checksum and Cyclic
Redundancy Check (CRC).
Parity Check
The parity check is done by adding an extra bit, called parity bit to the data to make a number of
1s either even in case of even parity or odd in case of odd parity.
While creating a frame, the sender counts the number of 1s in it and adds the parity bit in the
following way

• In case of even parity: If a number of 1s is even then parity bit value is 0. If the number of
1s is odd then parity bit value is 1.

• In case of odd parity: If a number of 1s is odd then parity bit value is 0. If a number of 1s
is even then parity bit value is 1.
On receiving a frame, the receiver counts the number of 1s in it. In case of even parity check, if
the count of 1s is even, the frame is accepted, otherwise, it is rejected. A similar rule is adopted
for odd parity check.
The parity check is suitable for single bit error detection only.
Checksum
In this error detection scheme, the following procedure is applied

• Data is divided into fixed sized frames or segments.

• The sender adds the segments using 1’s complement arithmetic to get the sum. It then
complements the sum to get the checksum and sends it along with the data frames.

• The receiver adds the incoming segments along with the checksum using 1’s complement
arithmetic to get the sum and then complements it.

• If the result is zero, the received frames are accepted; otherwise, they are discarded.
Cyclic Redundancy Check (CRC)
Cyclic Redundancy Check (CRC) involves binary division of the data bits being sent by a
predetermined divisor agreed upon by the communicating system. The divisor is generated using
polynomials.

• Here, the sender performs binary division of the data segment by the divisor. It then
appends the remainder called CRC bits to the end of the data segment. This makes the
resulting data unit exactly divisible by the divisor.

• The receiver divides the incoming data unit by the divisor. If there is no remainder, the data
unit is assumed to be correct and is accepted. Otherwise, it is understood that the data is
corrupted and is therefore rejected.
Error Correction Techniques
Error correction techniques find out the exact number of bits that have been corrupted and as well
as their locations. There are two principle ways

• Backward Error Correction (Retransmission) − If the receiver detects an error in the


incoming frame, it requests the sender to retransmit the frame. It is a relatively simple
technique. But it can be efficiently used only where retransmitting is not expensive as in
fiber optics and the time for retransmission is low relative to the requirements of the
application.
• Forward Error Correction − If the receiver detects some error in the incoming frame, it
executes error-correcting code that generates the actual frame. This saves bandwidth
required for retransmission. It is inevitable in real-time systems. However, if there are too
many errors, the frames need to be retransmitted.

2. Write short note on CRC

➔ CRC or Cyclic Redundancy Check is a method of detecting accidental changes/errors in the


communication channel.
CRC uses Generator Polynomial which is available on both sender and receiver side. An
example generator polynomial is of the form like x 3 + x + 1. This generator polynomial
represents key 1011. Another example is x 2 + 1 that represents key 101.

n : Number of bits in data to be sent


from sender side.
k : Number of bits in the key obtained
from generator polynomial.

Sender Side:
1. The binary data is first augmented by adding k-1 zeros in the end of the data
2. Use modulo-2 binary division to divide binary data by the key and store remainder
of division.
3. Append the remainder at the end of the data to form the encoded data and send the
same

Receiver Side (Check if there are errors introduced in transmission):

Perform modulo-2 division again and if the remainder is 0, then there are no errors.

3. Explain about hamming code.

➔ Hamming code is a set of error-correction codes that can be used to detect and correct the
errors that can occur when the data is moved or stored from the sender to the receiver. It is a
technique developed by R.W. Hamming for error correction.

General Algorithm of Hamming code –


s
The Hamming Code is simply the use of extra parity bits to allow the identification of an error.
1. Write the bit positions starting from 1 in binary form (1, 10, 11, 100, etc).
2. All the bit positions that are a power of 2 are marked as parity bits (1, 2, 4, 8, etc).
3. All the other bit positions are marked as data bits.
4. Each data bit is included in a unique set of parity bits, as determined its bit position
in binary form.
a. Parity bit 1 covers all the bits positions whose binary representation includes a 1
in the least significant
position (1, 3, 5, 7, 9, 11, etc).
b. Parity bit 2 covers all the bits positions whose binary representation includes a 1
in the second position from
the least significant bit (2, 3, 6, 7, 10, 11, etc).
c. Parity bit 4 covers all the bits positions whose binary representation includes a 1
in the third position from
the least significant bit (4–7, 12–15, 20–23, etc).
d. Parity bit 8 covers all the bits positions whose binary representation includes a 1
in the fourth position from
the least significant bit bits (8–15, 24–31, 40–47, etc).
e. In general, each parity bit covers all bits where the bitwise AND of the parity
position and the bit position is
non-zero.
5. Since we check for even parity set a parity bit to 1 if the total number of ones in the
positions it checks is
odd.
6. Set a parity bit to 0 if the total number of ones in the positions it checks is even.

You might also like