0% found this document useful (0 votes)
6 views

Computer_Networks_Ch5_DataLink_Layer

The document provides an overview of the Data Link Layer in computer networks, detailing its functions such as framing, error detection and correction, flow control, and access control. It discusses various methods of framing, including character/byte counting, byte stuffing, and bit stuffing, along with error detection mechanisms like parity bits and two-dimensional parity. The content is structured for educational purposes, aimed at students in computer science and engineering.

Uploaded by

dsushobhan8
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Computer_Networks_Ch5_DataLink_Layer

The document provides an overview of the Data Link Layer in computer networks, detailing its functions such as framing, error detection and correction, flow control, and access control. It discusses various methods of framing, including character/byte counting, byte stuffing, and bit stuffing, along with error detection mechanisms like parity bits and two-dimensional parity. The content is structured for educational purposes, aimed at students in computer science and engineering.

Uploaded by

dsushobhan8
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 78

Computer Networks

(PCC-CS 602)

Instructor

Bikash Choudhury
Assistant Professor
Department of Computer Science & Engineering
Ramkrishna Mahato Government Engineering College Purulia
Contents

Data Link Layer


 Framing
 Error Detection & Correction
 Flow Control & Error Control
 Random Access
 Multiple Access

Bikash Choudhury, 2023


Resources
1.Forouzan, B.A., Data Communications and Networking. 5th Edition.
2.Tanenbaum, Andrew S. and Wetherall, David J., Computer Networks. 5th Edition
3.https://www.wikipedia.org/
4.https://www.geeksforgeeks.org/

Bikash Choudhury, 2023


List of Layers

Bikash Choudhury, 2023


Data Link Layer

 The data link layer is responsible for moving frames from one hop (node) to the next.
Bikash Choudhury, 2023
Data Link Layer
• Framing: The data link layer divides the stream of bits received from the network
layer into manageable data units called frames.
• Physical Addressing: If frames are to be distributed to different systems on the
network, the data link layer adds a header to the frame to define the sender and/or
receiver of the frame. If the frame is intended for a system outside the sender’s
network, the receiver address is the address of the device that connects the
network to the next one.
• Flow Control: If the rate at which the data are absorbed by the receiver is less
than the rate at which data are produced in the sender, the data link layer imposes
a flow control mechanism to avoid overwhelming the receiver.
• Error Control: The data link layer adds reliability to the physical layer by adding
mechanisms to detect and retransmit damaged or lost frames. It also uses a
mechanism to recognize duplicate frames. Error control is normally achieved
through a trailer added to the end of the frame.
• Access Control: When two or more devices are connected to the same link, data
link layer protocols are necessary to determine which device has control over the
link at any given time.

Bikash Choudhury, 2023


Hop-to-Hop Delivery

Bikash Choudhury, 2023


Different Layers and Corresponding Data Name

Bikash Choudhury, 2023


Framing

https://www.tutorialspoint.com/framing-in-data-link-layer
Bikash Choudhury, 2023
Parts of a Frame

A frame has the following parts −


• Frame Header − It contains the source and the destination
addresses of the frame.
• Payload field − It contains the message to be delivered.
• Trailer − It contains the error detection and error correction
bits.
• Flag − It marks the beginning and end of the frame.

Bikash Choudhury, 2023


Framing Methods

Framing

Character/Byte Character/Byte Bit Stuffing


Count Stuffing

Bikash Choudhury, 2023


Character/Byte Counting
Uses a field in the header to specify the number of bytes in the frame. When the
datalink layer at the destination sees the byte count, it knows how many bytes
follow and hence where the end of the frame is.

Bikash Choudhury, 2023


Character/Byte Counting
Q. Consider the following sequence of data for character count-
51234567898012345687890123
If this frame arrives without any error, then calculate the number of
frame reach to the receiver?

Sol: Total number of frame is: 4


51234567898012345687890123
F1= 5 1 2 3 4
F2= 5 6 7 8 9
F3= 8 0 1 2 3 4 5 6
F4= 8 7 8 9 0 1 2 3
Bikash Choudhury, 2023
Character/Byte Counting
Q. In previous question let 5 is updated as 7 in frame
number-2 (F2) then calculate the total number of frame
received by the receiver?
Sol: Total number of frame is: 6
51234767898012345687890123
F1= 5 1 2 3 4
F2= 7 6 7 8 9 8 0
F3= 1
F4= 2 3
F5= 4 5 6 8
F6=7 8 9 0 1 2 3
Bikash Choudhury, 2023
Character/Byte Counting

• The trouble with the algorithm is that the count can be modified by a
transmission error.
• This leads to a synchronization problem.
• Character/Byte count method is rarely used.

Bikash Choudhury, 2023


Character / Byte Stuffing
Flag byte is used as both the starting and ending delimiter (Fig.A).
A byte is stuffed in the message to differentiate from the delimiter (Fig.B).

Bikash Choudhury, 2023


Character / Byte Stuffing

• Byte stuffing mechanism used in PPP (Point-to-Point Protocol) which


is used to carry packets over communications links.
• The size of the frame is increased if mire Flag characters are present in
the original data.

Bikash Choudhury, 2023


Bit Stuffing
Bit stuffing is the mechanism of inserting one or more non-information bits into a message
to be transmitted, to break up the message sequence, for synchronization purpose.

Bikash Choudhury, 2023


Bit Stuffing
Let Flag/End Delimiter (ED) = 01111 and if data = 01111
Sender stuffs a bit to break the pattern i.e., here appends a 0 in data =
011101.
Receiver receives the frame.
If data contains 011101, receiver removes the 0 and reads the data.
Q. If Data: 011100011110 and ED: 01111 then, find data after bit
stuffing ?
Ans: 01110000111010
Q. If Data: 110001001 and ED:1000 then, find data after bit stuffing
?
Ans: 11001010011
Bikash Choudhury, 2023
Bit Stuffing
Q. A bit-stuffing based framing protocol uses an 8-bit delimiter pattern of
01111110. If the output bit-string after stuffing is 01111100101, then the
input bit-string is (Gate 2014)
(A) 0111110100
(B) 0111110101
(C) 0111111101
(D) 0111111111
Sol: (B)
8-bit delimiter pattern is 01111110. The output bit-string after stuffing is
01111100101. The above highlighted bit is stuffed bit. So, input bit-string
must be 0111110101.

Bikash Choudhury, 2023


Bit Stuffing
Q. In a data link protocol, the frame delimiter flag is given by 0111.
Assuming that bit stuffing is employed, the transmitter sends the data
sequence 01110110 as (GATE 2004)
(A) 01101011
(B) 011010110
(C) 011101100
(D) 0110101100
Sol: (D)
Delimiter flag: 0111
Data sequence: 01110110
So, for a flag of 4 bits we will compare data sequence with pattern of 3
bits i.e., 011.
0110101100
Bikash Choudhury, 2023
Bit Stuffing

• Bit stuffing was developed for the HDLC (High-Level Data Link
Control) protocol. Each frame begins and ends with a special bit
pattern, 01111110. This pattern is a flag byte.
• The length of the frame in both byte/bit stuffing depends on the
contents of the data it carries.

Bikash Choudhury, 2023


Error Detection and Correction
Data can be corrupted during transmission. Some applications
require that errors be detected and corrected.

Error in Datalink layer:

Sender 1010 1001 Receiver

Errors

Single Bit Multiple Bits/Burst Error


Bikash Choudhury, 2023
Single Bit Error

In a single-bit error, only 1 bit in the data unit has changed.

Bikash Choudhury, 2023


Multiple Bits / Burst Error

A burst error means that 2 or more bits in the data unit


have changed.

Bikash Choudhury, 2023


Error Detection Mechanism

Error
Detection

Cyclic
Parity Bit Redundancy Checksum
Check (CRC)

Bikash Choudhury, 2023


Error Detection Mechanism
To detect or correct errors, we need to send extra (redundant)
bits with data.

Bikash Choudhury, 2023


Error Detection (Parity Bit)

• It is a control bit generated by the data-link layer.


• Two different types of parity (Odd and Even) is available.
• If the total number of ‘1’ in a data including parity bit is odd,
then it is called odd parity.
• If the total number of ‘1’ in a data including parity bit is even,
then it is called even parity.

we divide our message into blocks, each of k bits, called datawords. We add r
redundant bits to each block to make the length n = k + r. The resulting n-bit blocks
are called codewords.
Bikash Choudhury, 2023
Error Detection (Odd & Even Parity Bit)
Data Even Parity Odd Parity
000 0 1
001 1 0
010 1 0
011 0 1
100 1 0
101 0 1
110 0 1
111 1 0

Code word= original data word + parity bit


Code word=1111 (Data word:111 & Parity bit (even): 1)

Bikash Choudhury, 2023


Error Detection (Odd & Even Parity Bit)
• Parity bit can detect all single bit errors but cannot detects the place of error.
• In each frame one parity bit is required.
• It can detect odd number of errors.

Odd and Even Number of Errors


Dataword:101100
Codeword (Applied even parity): 1011001
Codeword with single bit error: 1010001
Codeword with single bit error: 1111001
Codeword with multiple bits error (odd changes): 1010100
Codeword with multiple bits (even changes): 1000010

Bikash Choudhury, 2023


Two-Dimensional Parity (2D-Parity)

• 2D parity is the enhanced version of 1D parity.


• This mechanism works with multiple data units simultaneously.
• Parity check bits are computed for each row, which is equivalent to the single-
parity check.
• In Two-Dimensional Parity check, a block of bits is divided into rows, and the
redundant row of bits is added to the whole block.
• At the receiving end, the parity bits are compared with the parity bits computed
from the received data.

Bikash Choudhury, 2023


Example: 2D-Parity

Bikash Choudhury, 2023


Example: 2D-Parity

Received Data:

After computing the 2D parity if both Row and Column parities are matched with the
received parity then the received data is not corrupted
Bikash Choudhury, 2023
Example: 2D-Parity (2 bits error)
Received Data: 100101010 111000100 001001000 100001000 110110110

1 0 0 1 0 1 0 1 0 0
1 1 1 0 0 0 1 0 0 0
0 0 1 0 0 1 0 0 0 0
1 0 0 0 0 1 0 0 0 0
1 1 0 1 0 1 1 1 0 0

After computing the 2D parity if both Row and Column parities are matched with the
received parity then the received data is not corrupted. Here we received 2 error bits.

Bikash Choudhury, 2023


Example: 2D-Parity (4 bits error)
Received Data: 100101010 111000100 001010000 100001000 110110110

1 0 0 1 0 1 0 1 0 0
1 1 1 0 0 0 1 0 0 0
0 0 1 0 1 0 0 0 0 0
1 0 0 0 0 1 0 0 0 0
1 1 0 1 1 0 1 1 0 0

After computing the 2D parity if both Row and Column parities are matched with the
received parity then the received data is not corrupted. Here we received no error bits.

4 or more than 4 bits error can not be detected by 2D parity.


Bikash Choudhury, 2023
Example: 2D-Parity (4 bits error)
Q. Data transmitted on a link uses the following 2D parity scheme for
error detection: Each sequence of 28 bits is arranged in a 4×7 matrix
(rows r0 through r3, and columns d7 through d1) and is padded with a
column d0 and row r4 of parity bits computed using the Even parity
scheme. Each bit of column d0 (respectively, row r4) gives the parity of
the corresponding row (respectively, column). These 40 bits are
transmitted over the data link.

The table shows data received by a receiver and has n corrupted bits. What is the mini-
mum possible value of n? GATE-2008
(A) 1 (B) 2 (C) 3 (D) 4 Bikash Choudhury, 2023
Example: 2D-Parity (4 bits error)
d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0

r0 0 1 0 1 0 0 1 1 r0 0 1 0 1 0 0 1 1

r1 1 1 0 0 1 1 1 0 r1 1 1 0 0 1 1 1 0

r2 0 0 0 1 0 1 0 0 r2 0 0 0 1 0 1 0 0

r3 0 1 1 0 1 0 1 0 r3 0 1 1 0 1 0 1 0

r4 1 1 0 0 0 1 1 0 r4 1 1 0 0 0 1 1 0

Bikash Choudhury, 2023


Example: 2D-Parity (4 bits error)
d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0

r0 0 1 0 1 0 0 1 1 r0 0 1 0 1 0 0 1 1

r1 1 1 0 0 1 1 1 0 r1 1 1 0 0 1 1 1 0

r2 0 0 0 1 0 1 0 0 r2 0 0 0 1 0 1 0 0

r3 0 1 1 0 1 0 1 0 r3 0 1 1 0 1 0 1 0

r4 1 1 0 0 0 1 1 0 r4 1 1 0 0 0 1 1 0

Bikash Choudhury, 2023


Summary: 2D-Parity
• If two bits in one data unit are corrupted and two bits exactly
the same position in another data unit are also corrupted, then
2D Parity checker will not be able to detect the error.
• This technique cannot be used to detect the 4-bit errors or
more in some cases.

Bikash Choudhury, 2023


Cyclic Redundancy Check (CRC)
• Cyclic Redundancy Check (CRC) is a block code that was invented by W.
Wesley Peterson in 1961. It is commonly used to detect accidental changes
to data transmitted via telecommunications networks and storage devices.
• 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. So, CRC is also called polynomial code checksum.
• Before sending the message over network channels, the sender encodes the
message using CRC. The receiver decodes the incoming message to detect
error. If the message is error-free, then it is accepted, otherwise, the receiver
asks for re-transmission of the message.

https://www.tutorialspoint.com/what-is-algorithm-for-computing-the-crc

Bikash Choudhury, 2023


Cyclic Redundancy Check (CRC)

Bikash Choudhury, 2023


Cyclic Redundancy Check (CRC)

Bikash Choudhury, 2023


Cyclic Redundancy Check (CRC)

Algorithm for Encoding using CRC


1. The communicating parties agrees upon the size of message,
M(x) and the generator polynomial, G(x).
2. If r is the order of G(x),r, bits are appended to the low order end
of M(x). This makes the block size bits, the value of which is xrM(x).
3. The block xrM(x) is divided by G(x) using modulo 2 division.
4. The remainder after division is added to xrM(x) using modulo 2
addition. The result is the frame to be transmitted, T(x). The
encoding procedure makes exactly divisible by G(x).

Bikash Choudhury, 2023


Cyclic Redundancy Check (CRC)

Algorithm for Decoding using CRC


1. The receiver divides the incoming data frame T(x) unit by G(x)
using modulo 2 division. Mathematically, if E(x) is the error, then
modulo 2 division of [M(x) + E(x)] by G(x) is done.
2. If there is no remainder, then it implies that E(x). The data frame is
accepted.
3. A remainder indicates a non-zero value of E(x), or in other words
presence of an error. So, the data frame is rejected. The receiver may
then send an erroneous acknowledgment back to the sender for
retransmission.

Bikash Choudhury, 2023


CRC Generator- Error Detection (CRC)
• CRC generator is an algebraic polynomial represented as a bit pattern.
• Bit pattern is obtained from the CRC generator using the following rule-
Consider the CRC generator is x6 + x + 1.
The corresponding binary pattern is obtained as-

Thus, for the given CRC generator, the corresponding binary pattern is 1000011

Bikash Choudhury, 2023


XORing of two single bits or two words

Bikash Choudhury, 2023


Cyclic Redundancy Check (CRC)

Message (M): 1001


Generator (G):1011
Appends bits:000
M(Appended):1001000
CRC: 110
Code Data: 1001110

Append bits depends on the number


of bits present in the generator. Here
generator consists 4 (1011) bits so, the
number of bits will be appending (n-1)
or (4-1) = 3 (no. of zeroes); where
n = Number of bits present in the
generator.

Bikash Choudhury, 2023


Cyclic Redundancy Check (CRC)

Bikash Choudhury, 2023


Example: Error Detection (CRC)

Q. The message “ 11001001” is to be transmitted using CRC


polynomial X3 +1 to protect it from errors, the message that should be
transmitted is: (GATE)
I) 11001001000 III) 11001010
II) 11001001011 IV) 110010010011
Sol: II) 11001001011
Message (M): 11001001
CRC Polynomial = X3 +1 = 1. X3 + 0.X2 +0.X1 + 1.X0 = 1001

Bikash Choudhury, 2023


Error Detection (CRC)
Message (M): 11001001
Generator (G):1001
Appends bits:000
M(Appended):11001001000
CRC: 011
Code Data: 11001001011

Bikash Choudhury, 2023


Error Detection (CRC)
How to check is there any error or not?
Code Data: 11001001011
Generator(G):1001
Remainder: 000

If all bits in remainder are


zero, then data received
with no error.

Bikash Choudhury, 2023


Error Detection (CRC)
Consider the data received with error.
Transmitted Data: 11001001
Received Data: 11000001
Generator:1001
Remainder:001

If all bits in remainder is zero,


then data received with no error.
But here the remainder is 001, it
means received data is
corrupted.

Bikash Choudhury, 2023


Error Detection (CRC)
Q. A computer network uses polynomial over GF(2) for error
checking with 8 bits as information bits and uses x3 + x + 1 as
the generator polynomial to generate the check bits. In this
network, the message 01011011 is transmitted as: (GATE)
(A) 01011011010
(B) 01011011011
(C) 01011011101
(D) 01011011100
Ans: (C) 01011011101
(Please go to the next page for solution)

Bikash Choudhury, 2023


Bikash Choudhury, 2023
Error Detection (CRC)
Q. Consider the following message M = 1010001101. The cyclic
redundancy check (CRC) for this message using the divisor polynomial
x5 + x4 + x2 + 1 is : (GATE)
(A) 01110
(B) 01011
(C) 10101
(D) 10110

Ans: (A) 01110


(Please go to the next page for solution)

Bikash Choudhury, 2023


Bikash Choudhury, 2023
Summary of Error Detection (CRC)
• If the generator has more than one term and the coefficient of x0 is 1, all
single errors can be caught.
• If a generator cannot divide xt + 1 (t between 0 and n – 1), then all
isolated double errors can be detected.
• A generator that contains a factor of x + 1 can detect all odd-numbered
errors.
• All burst errors with L ≤ r will be detected.
• All burst errors with L = r + 1 will be detected with probability
1 – (1/2)r–1.
• All burst errors with L > r + 1 will be detected with probability
1 – (1/2)r.

Bikash Choudhury, 2023


Checksum
This is a block code method where a checksum is created based on the
data values in the data blocks to be transmitted using some algorithm
and appended to the data. When the receiver gets this data, a new
checksum is calculated and compared with the existing checksum. A
non-match indicates an error.
Error Detection by Checksums
For error detection by checksums, data is divided into fixed sized frames or
segments.
Sender’s End − 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.
Receiver’s End − 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.
Bikash Choudhury, 2023
Checksum
• Suppose that the sender wants to send 4 frames each of 8 bits, where
the frames are 11001100, 10101010, 11110000 and 11000011.
• The sender adds the bits using 1s complement arithmetic. While
adding two numbers using 1s complement arithmetic, if there is a
carry over, it is added to the sum.
• After adding all the 4 frames, the sender complements the sum to get
the checksum, 11010011, and sends it along with the data frames.
• The receiver performs 1s complement arithmetic sum of all the frames
including the checksum. The result is complemented and found to be
0. Hence, the receiver assumes that no error has occurred.

Bikash Choudhury, 2023


Checksum

Bikash Choudhury, 2023


Summary of Checksum

• The checksum detects all errors involving an odd number of


bits.
• It also detects most errors involving even number of bits.
• If one or more bits of a segment is damaged and the
corresponding bit or bits of opposite value in a second
segment are also damaged, the sum of those columns will not
be changed, and the receiver will not detect the errors.

Bikash Choudhury, 2023


Hamming Distance
The Hamming distance between two words is the number of
differences between corresponding bits.
Let us find the Hamming distance between two pairs of words.

1. The Hamming distance d(000, 011) is 2 because


000
011
011

2. The Hamming distance d(10101, 11110) is 3 because


10101
11110
01011
Bikash Choudhury, 2023
The Minimum Hamming Distance
The minimum Hamming distance is the smallest Hamming distance
between all possible pairs in a set of words.
Data Word (k=2 bits) Code Word (Applied Even Parity) (n=3 bits)
00 000
01 011
10 101
11 110

Find the minimum Hamming distance of the coding scheme in Table.


Solution: We first find all Hamming distances.

The dmin in this case is 2.


Bikash Choudhury, 2023
The Minimum Hamming Distance
Data Word (k=2 bits) Code Word (Error Correction) (n=5bits)
00 00000
01 01011
10 10101
11 11110
Find the minimum Hamming distance of the coding scheme in Table
Solution: We first find all the Hamming distances.

The dmin in this case is 3.

To guarantee the detection of up to t errors in all cases, the minimum


Hamming distance in a block code must be dmin = t + 1.
Bikash Choudhury, 2023
The Minimum Hamming Distance
The minimum Hamming distance for the first table is 2. This code
guarantees detection of only a single error. For example, if the third
codeword (101) is sent and one error occurs, the received codeword does
not match any valid codeword. If two errors occur, however, the received
codeword may match a valid codeword and the errors are not detected.
The minimum Hamming distance for the second table is dmin = 3. This
code can detect up to two errors. Again, we see that when any of the
valid codewords is sent, two errors create a codeword which is not in the
table of valid codewords. The receiver cannot be fooled.
However, some combinations of three errors change a valid codeword to
another valid codeword. The receiver accepts the received codeword and
the errors are undetected.
Bikash Choudhury, 2023
The Minimum Hamming Distance
To guarantee the detection of up to t errors in all cases, the minimum
Hamming distance in a block code must be dmin = t + 1.
To guarantee correction of up to t errors in all cases, the minimum
Hamming distance in a block code must be dmin = 2t + 1.

Q. A code scheme has a Hamming distance dmin = 4. What is the error


detection and correction capability of this scheme?
Solution : This code guarantees the detection of up to three errors (t =
3), but it can correct up to one error. In other words, if this code is used
for error correction, part of its capability is wasted. Error correction
codes need to have an odd minimum distance (3, 5, 7, . . . ).
Bikash Choudhury, 2023
Hamming Code for Error Detection & Correction
We can detect and correct the error using Hamming Code.
The Structure of 7-bit Hamming Code
D4 D3 D2 P3 D1 P2 P1
D = Data Bits
P = Parity Bits
D7 D6 D5 P4 D3 P2 P1

D4 D3 D2 22 D1 21 20

All bit position that


are power of 2
Data Bits Parity Bits

Bikash Choudhury, 2023


Hamming Code for Error Detection & Correction
The Relationship Between Data Bits and Parity Bits:
2P ≥ D+P+1 D= No. of Message Bits P = No. of Parity Bits

Q. Consider a message 1001, is to be encoded using Hamming code. Then


calculate the no. of required parity bits.

Sol:
We know, 2P ≥ D+P+1
2P ≥ 4+P+1 [D=4]
23 ≥ 4+3+1 [Consider P=3]
8 ≥8 [Satisfied]

The number of required parity bits are 3

Bikash Choudhury, 2023


Hamming Code for Error Detection & Correction
How to calculate the parity bits?
P3 P2 P1 Value
D7 D6 D5 P4 D3 P2 P1
0 0 1 1
P1 = 1,3,5,7 I: First place the data bits according to the mentioned places.
II: Then calculate the parity (odd or even). 0 1 0 2
P2 = 2,3,6,7
III: The extra (or parity bit) value will be the value of parity. 0 1 1 3
P4 = 4,5,6,7
1 0 0 4
Q. Consider a message 1011, is to be encoded using Hamming
code. Then calculate the required parity bits. 1 0 1 5
1 1 0 6
D7 =1 D6= 0 D5=1 P4=? D3 = 1 P2=? P1=?
1 1 1 7
P1 1 3 5 7 P1 P1 1 1 1 P1 1 1 1 1
Here we applied
P2 2 3 6 7 P2 P2 1 0 1 P2 0 1 0 1
even parity
P4 4 5 6 7 P4 P4 1 0 1 P4 0 1 0 1

D7 =1 D6= 0 D5=1 P4=0 D3 = 1 P2=0 P1=1 Encoded Data: 1010101


Bikash Choudhury, 2023
Hamming Code for Error Detection & Correction
Q. A 7-bit Hamming code is received as 1010101, assume even parity applied. Find
out whether received code is correct or wrong? If wrong find out the location of
the error.

Sol: D7 =1 D6= 0 D5=1 P4=0 D3 = 1 P2=0 P1=1

P1 1 3 5 7 P1 1 1 1 1 P1 = 0 All parity bits is zero


(P1, P2, P4 = 0). The
P2 2 3 6 7 P2 0 1 0 1 P2 = 0 received code is correct
P4 4 5 6 7 P4 0 1 0 1 P4 = 0

The received code is correct.

Bikash Choudhury, 2023


Hamming Code for Error Detection & Correction
Q. A 7-bit Hamming code is received as 1011101, assume even parity applied on
the code. Find out whether received code is correct or wrong? If wrong, find out
the location of the error and correct the error.

Sol: D7 =1 D6= 0 D5=1 P4=1 D3 = 1 P2=0 P1=1

P1 1 3 5 7 P1 1 1 1 1 P1 = 0 Here one parity bit is


nonzero (P4 = 1). The
P2 2 3 6 7 P2 0 1 0 1 P2 = 0 received code is incorrect

P4 4 5 6 7 P4 1 1 0 1 P4 = 1

The Location of the Error Location 7 6 5 4 3 2 1


P4 P2 P1 Location of the Error Error 1 0 1 1 1 0 1
1 0 0 4 (Decimal of 100) Correction 1 0 1 0 1 0 1

The corrected data is : 1010101


Bikash Choudhury, 2023
Hamming Code for Error Detection & Correction
Q. An error correcting code has the following code words:
00000000, 00001111, 01010101, 10101010, 11110000.
What is the maximum number of bit errors that can be corrected ? (GATE)
(A) 0 (B) 1 (C) 2 (D) 3

Solution: We first find all the Hamming distances


d(0000 0000, 0000 1111) = 4 d(0000 0000, 0101 0101) = 4 d(0000 0000, 1010 1010) = 4
d(0000 0000, 1111 0000) = 4 d(0000 1111, 0101 0101) = 4 d(0000 1111, 1010 1010) = 4
d(0000 1111, 1111 0000) = 8 d(0101 0101, 1010 1010) = 8 d(0101 0101, 1111 0000) = 4
d(1010 1010, 1111 0000) = 4 ■ dmin= 4
To guarantee correction of up to t errors in all cases, the minimum
Hamming distance in a block code must be dmin = 2t + 1.

dmin = 2t + 1 => 4 = 2t +1 => 2t = 4-1 => t = 3/2 => t = 1.5 = 1

Correct Answer is option (B) 1


Bikash Choudhury, 2023
Hamming Code for Error Detection & Correction
Q. A 12-bit codeword is generated using Hamming code to detect 2-bit errors
and correct 1 bit error in 8-bit data. The 12-bit codeword (generated ) is
corrupted to give 1110 0000 1010. Select from the following options the
originally generated codeword (consider even parity applied): 0 0 0 1 1
a) 1010 0000 0010 b) 1000 0000 1010 0 0 1 0 2
c) 1010 0000 1010 d) 1010 0000 1011 0 0 1 1 3
1 1 1 0 0 0 0 0 1 0 1 0 0 1 0 0 4
D12 D11 D10 D9 P8 D7 D6 D5 P4 D3 P2 P1 0 1 0 1 5
23 22 21 20 0 1 1 0 6
0 1 1 1 7
P1 = 1,3,5,7,9,11 = 0 0 0 0 0 1 = 1
Error 1 0 0 0 8
P2 = 2,3,6,7,10,11 = 1 0 0 0 1 1= 1 P8 P4 P2 P1
1 0 1 1 11 1 0 0 1 9
P4 = 4,5,6,7,12 = 1 0 0 0 1 = 0
1 0 1 0 10
P8 = 8,9,10,11,12 = 0 0 1 1 1 = 1
1 0 1 1 11
D12=1 D11=1 D10=1 D9=0 P8=0 D7=0 D6=0 D5=0 P4=1 D3=0 P2=1 P1=0
1 1 0 0 12
1 0 1 0 0 0 0 0 1 0 1 0 1 1 0 1 13
Option (c) is correct (1010 0000 1010) Bikash Choudhury, 2023
Hamming Code for Double Error Detection & Single Correction
The Hamming code can be modified to correct a single error and detect
double errors by adding a parity bit as the MSB, which is the XOR of all
other bits.

Sl. P (Parity Bit) C (Extra Parity Bit) Output


No. C= XOR(CodeWord)
1 P=0 C=0 No Error
2 P≠0 C=1 Single Error occurred that can be corrected
3 P≠0 C= 0 Double error occurred that can be detected but can bot be corrected

4 P=0 C=1 An error occurred in extra parity bit

Bikash Choudhury, 2023


Hamming Code for Double Error Detection & Single Correction

A 7-bit Hamming code is generated as 1010101, assume even parity applied.


Find out the extra parity bit (C(n+1)): XOR(1010101) = 0
The new code ward which will be transmitted : 0 1010101
P1 1 3 5 7 P1 1 1 1 1 P1 = 0

P2 2 3 6 7 P2 0 1 0 1 P2 = 0

P4 4 5 6 7 P4 0 1 0 1 P4 = 0

Calculate P = P1 P2 P3 = 0 0 0 = 0 P = 0 and C=0 it means there is no any error


Calculate C =XOR(01010101) = 0

Bikash Choudhury, 2023


Hamming Code for Double Error Detection & Single Correction
A 7-bit Hamming code is generated as 1010101, assume even parity applied.
Find out the extra parity bit (C(n+1)): XOR(1010101) = 0
The new code ward which will be transmitted : 0 1010101
Consider that one bit is corrupted: : 0 1010111
P1 1 3 5 7 P1 1 1 1 1 P1 = 0

P2 2 3 6 7 P2 1 1 0 1 P2 = 1

P4 4 5 6 7 P4 0 1 0 1 P4 = 0

Calculate P = P1 P2 P3 = 0 1 0 = 2 P = 010 = 2 and C=1 it means there is one error


Calculate C =XOR(01010111) = 1 in bit position 2
The Corrected code is: 1010101

Bikash Choudhury, 2023


Hamming Code for Double Error Detection & Single Correction
A 7-bit Hamming code is generated as 1010101, assume even parity applied.
Find out the extra parity bit (C(n+1)): XOR(1010101) = 0
The new code ward which will be transmitted : 0 1010101
Consider that two bits are corrupted: : 0 1010011
P1 1 3 5 7 P1 1 0 1 1 P1 = 1

P2 2 3 6 7 P2 1 0 0 1 P2 = 0

P4 4 5 6 7 P4 0 1 0 1 P4 = 0

Calculate P = P1 P2 P3 = 1 0 0 = 4 P = 100 = 4 and C=0 it means Double error


Calculate C =XOR(0 1010011 ) = 0 occurred that can be detected but can not be
corrected

Bikash Choudhury, 2023


Hamming Code for Double Error Detection & Single Correction
A 7-bit Hamming code is generated as 1010101, assume even parity applied.
Find out the extra parity bit (C(n+1)): XOR(1010101) = 0
The new code ward which will be transmitted : 0 1010101
Consider that extra parity bit is corrupted: : 1 1010101
P1 1 3 5 7 P1 1 1 1 1 P1 = 0

P2 2 3 6 7 P2 0 1 0 1 P2 = 0

P4 4 5 6 7 P4 0 1 0 1 P4 = 0

Calculate P = P1 P2 P3 = 0 0 0 = 0 P = 000 = 0 and C=1 it means an error occurred in


Calculate C =XOR(1 1010011 ) = 1 extra parity bit

Bikash Choudhury, 2023

You might also like