hamming code examples

12
Hamming Code Examples This is VERY tricky to get you head around BUT simple once you know what’s happening!!!

Upload: nuckl

Post on 16-Apr-2015

89 views

Category:

Documents


4 download

DESCRIPTION

hamming code

TRANSCRIPT

Page 1: hamming code examples

Hamming Code Examples

This is VERY tricky to get you head around BUT simple once you know what’s happening!!!

Page 2: hamming code examples

Assumptions

• You know what an even parity bit check is

• You know what binary is

• You know that a binary “word” could represent almost anything

• Original ASCII comprises of 7-bits

• You have read the intro to hamming on page113 of Bond & Langfield

Page 3: hamming code examples

How it works?

• Each data item is check by at least two parity bits…

• By doing multiple checks we can see which bit is wrong!!!

Page 4: hamming code examples

Using Hamming Code Checks

• Lets start with 4 bits of Data• This would require 3 parity bits (7bits total)• Parity bits are placed in positions 2n

• Hamming Checks– Start at n Check n Skip n– E.g. Parity bit 2 is in position 2 so…– Start at 2, check two positions, skip two positions, etc..– 2,3,6,7 are part of the pattern that P2 checks

Positionn 7 6 5 4 3 2 1

What’s There

Data Bit 4

Data Bit 3

Data Bit 2

Parity Bit 3

(P3)

Data Bit 1

Parity Bit 2

(P2)

Parity Bit 1

(P1)

Page 5: hamming code examples

Hamming Code Check example

• I get sent a 7 bit binary word: 0101101• Need to check that there is even parity for each

of the three parity bit patternPosition

n 7 6 5 4 3 2 1

Word 0 1 0 1 1 0 1

P1 0 0 1 1

P2 0 1 1 0

P3 0 1 0 1

P1 is in position 1 so… Start at 1, check 1, skip 1, check 1 skip 1 etc..(1,3,5,7)P2 is in position 2 so… Start at 2 check 2, skip 2 check 2 skip 2 rtc..(2,3,6,7)

P3 is in position 4 so…Start at 4, check 4 skip 4(then we run out of bits) (4,5,6,7)

All three have “Even Parity” so this is a Correct pattern

Page 6: hamming code examples

Hamming Code Check example 2

• I get sent a 7 bit binary word: 0001101• Need to check that there is even parity for each

of the three parity bit patternPosition

n 7 6 5 4 3 2 1

Word 0 0 0 1 1 0 1

P1 0 0 1 1

P2 0 0 1 0

P3 0 0 0 1

P1 is in position 1 so… Start at 1, check 1, skip 1, check 1 skip 1 etc..(1,3,5,7)P2 is in position 2 so… Start at 2 check 2, skip 2 check 2 skip 2 rtc..(2,3,6,7)

P3 is in position 4 so…Start at 4, check 4 skip 4(then we run out of bits) (4,5,6,7)

x

x

P2 and P3 don’t have “Even Parity” so this is NOT a correct pattern

Page 7: hamming code examples

QUIZ!!

Have a go at the 4bit Hamming Checks quiz on Godalming Online

before you move on!

Page 8: hamming code examples

4 bit Creation Example - 1101

Position

n7 6 5 4 3 2 1

What’s There

Data Bit 4 Data Bit 3 Data Bit 2 Parity Bit 3

(P3)

Data Bit 1 Parity Bit 2

(P2)

Parity Bit 1

(P1)

1 1 0 1

1 1 0 1 0

1 1 0 1 1

1 1 0 0 1

1 1 0 0 1 1 0

•Parity bit 1 is in position 1

•So it is part of the pattern 1,3,5,7 (check 1, skip 1)

• this has the bits 101 currently so we add a 0 to keep even parity•Parity bit 2 is in position 2

•So it is part of the pattern 2,3,6,7 (check 2, skip 2)

• this has the bits 111 currently so we add a 1 to keep even parity•Parity bit 3 is in position 4

•So it is part of the pattern 4,5,6,7 (check 4, skip 4) (although we only have 7bits)

• this has the bits 110 currently so we add a 0 to keep even parity

•The Final bit pattern sent is… 1100110

•This includes the 4 data bits and three parity bits

•Start by placing the 4 data bits in the correct positions

•Leave spaces for the parity bits

Page 9: hamming code examples

Why Bother?

• This seems A LOT of processing and redundant data just to validate a nibble

• Hamming Codes can “FIX” one bit of incorrect data!!!!!!!!!

• Hamming is an ERROR CORRECTION code

Page 10: hamming code examples

Remember this

• I get sent a 7 bit binary word: 0001101• Need to check that there is even parity for each

of the three parity bit patternPosition

n 7 6 5 4 3 2 1

Word 0 0 0 1 1 0 1

P1 0 0 1 1

P2 0 0 1 0

P3 0 0 0 1

P1 is in position 1 so… Start at 1, check 1, skip 1, check 1 skip 1 etc..(1,3,5,7)P2 is in position 2 so… Start at 2 check 2, skip 2 check 2 skip 2 rtc..(2,3,6,7)

P3 is in position 4 so…Start at 4, check 4 skip 4(then we run out of bits) (4,5,6,7)

x

x

P2 and P3 don’t have “Even Parity” so this is NOT a correct pattern

Page 11: hamming code examples

Which bit is wrong???

Positionn 7 6 5 4 3 2 1

Word 0 0 0 1 1 0 1

P1 0 0 1 1

P2 0 0 1 0

P3 0 0 0 1

• Now add up the positions of the WRONG bits• P2 is position 2 and P3 is position 4 2+4 = 6• Bit6 needs to be “flipped” from 0 to 1• Check your self that this now is correct

x

x

Page 12: hamming code examples

NOW

• Try changing another data bi in the Patten and see if the hamming

• Have a go at the example in B&L