Assignment No. 3: Title: Lab Assignment On Unit II: (Use C/C++)
Assignment No. 3: 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
• 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
• 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
• 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
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
Perform modulo-2 division again and if the remainder is 0, then there are no errors.
➔ 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.