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

Lab Bitstff, Hamming Code

1. Hamming codes add parity bits to data words to enable error detection and correction. The bit positions used for parity bits are powers of two. (2. Hamming codes calculate parity bits by taking the XOR of specific bits in the data word. 3. Errors can be detected by recalculating the parity bits and comparing them to the received parity bits. If they differ, the position of the error bit is given by the decimal value of the differing parity bits.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

Lab Bitstff, Hamming Code

1. Hamming codes add parity bits to data words to enable error detection and correction. The bit positions used for parity bits are powers of two. (2. Hamming codes calculate parity bits by taking the XOR of specific bits in the data word. 3. Errors can be detected by recalculating the parity bits and comparing them to the received parity bits. If they differ, the position of the error bit is given by the decimal value of the differing parity bits.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 9

Framing

Break bit stream from physical layer into frames


for error detection and recovery.

Four framing methods


1.Character count
2.Flag bytes with byte (character) stuffing
3.Starting and ending flags, with bit stuffing
4.Physical layer coding violations

2
Bit Stuffing
• Each frame begins and ends with a special bit pattern
called a flag byte [01111110]. {Note this is 7E in hex}
• Whenever sender data link layer encounters five
consecutive ones in the data stream, it automatically stuffs
a 0 bit into the outgoing stream.
• When the receiver sees five consecutive incoming ones
followed by a 0 bit, it automatically destuffs the 0 bit
before sending the data to the network layer.

• Example of bit stuffing –


Bit sequence: 110101111101011111101011111110
(without bit stuffing)
Bit sequence: 110101111100101111101010111110110
(with bit stuffing)
• After 5 consecutive 1-bits, a 0-bit is stuffed. Stuffed bits
are marked bold.
Computer Networks: Bit and Byte Stuffing 3
Algorithm for Bit−Stuffing
1. Start
2. Initialize the array for transmitted stream with the special bit
pattern 0111 1110 which indicates the beginning of the frame.
3. Get the bit stream to be transmitted in to the array.
4. Check for five consecutive ones and if they occur, stuff a bit 0
5. Display the data transmitted as it appears on the data line after
appending 0111 1110 at the end
6. For de−stuffing, copy the transmitted data to another array after
detecting the stuffed bits
7. Display the received bit stream
8. Stop
Bit Stuffing
Input Stream

0110111111100111110111111111100000

Stuffed Stream

01101111101100111110011111011111000000

Stuffed bits
Unstuffed Stream

0110111111100111110111111111100000

Computer Networks: Bit and Byte Stuffing 5


Hamming Code
• Most common types of error-correcting codes
used in RAM
• devised by R. W. Hamming.
• In the Hamming code, k parity bits are added
to an n-bit data word, forming a new word of
n +k bits. The bit positions are numbered in
sequence from 1 to n + k.
• Positions numbered with powers of two are
reserved for the parity bits.(20,21,22,23,24..)
• Remaining bits are the data bits.
Example
Bit position 1 2 3 4 5 6 7 8 9 10 11 12
Bits P1 P2 1 P4 1 0 0 P8 0 1 0 0

P1 XOR of bits (3, 5, 7, 9, 11) = 1⊕1⊕0⊕0⊕0⊕=0


P2 XOR of bits (3, 6, 7, 10, 11)=10010=0
P4 XOR of bits (5, 6, 7, 12) =1000=1
P8 XOR of bits (9, 10, 11, 12) =0100=1
exclusive-OR operation performs the odd function. It is equal to 1 for
an odd number of 1’s among the variables and to 0 for an even
number of 1’s. The 8-bit data word is written into the memory
together with the 4 parity bits as a 12-bit composite word.
When the 12 bits are read from memory, they are checked again for
errors.
Bit position 1 2 3 4 5 6 7 8 9 10 11 12
001 1100101 0 0
Error detection
The parity of the word is checked over the same
groups of bits, including their parity bits.
The four check bits are evaluated as follows:
C1 XOR of bits (1, 3, 5, 7, 9, 11)
=1⊕1⊕0⊕0⊕0⊕0
C2 XOR of bits (2, 3, 6, 7, 10,11)= 100100
C4 XOR of bits (4, 5, 6, 7, 12) = 10001
C8 XOR of bits (8, 9, 10, 11, 12) = 01001
Error Detection
For example, consider the following three cases:
In the first case, there is no error in the 12-bit word.
In the second case, an error in bit position number 1 because it changed from 0 to 1.
The third case , an error in bit position 5 with a change from 1 to 0.
Evaluating the XOR of the corresponding bits, we determine the four check bits to be as
follows:
. Bit position 1 2 3 4 5 6 7 8 9 10 11 12
0 0 1 1 1 0 0 1 0 1 0 0 No error
1 0 1 1 1 0 0 1 0 1 0 0 Error in bit 1
0 0 1 1 0 0 0 1 0 1 0 0 Error in bit 5
no error, C= 0000;
error in bit 1, C =0001;
error in bit 5, C =0101. Hence,
• when C is not equal to 0, the decimal value of C gives the position of the bit in error.
• The error can then be corrected by complementing the corresponding bit.
• The Hamming code can be used for data words of any length

You might also like