Hamming Code Examples

download Hamming Code Examples

of 12

description

Hamming Code Examples

Transcript of Hamming Code Examples

  • Hamming Code ExamplesThis is VERY tricky to get you head around BUT simple once you know whats happening!!!

  • AssumptionsYou know what an even parity bit check isYou know what binary isYou know that a binary word could represent almost anythingOriginal ASCII comprises of 7-bits You have read the intro to hamming on page113 of Bond & Langfield

  • How it works?Each data item is check by at least two parity bitsBy doing multiple checks we can see which bit is wrong!!!

  • Using Hamming Code ChecksLets start with 4 bits of DataThis would require 3 parity bits (7bits total)Parity bits are placed in positions 2nHamming ChecksStart at n Check n Skip nE.g. Parity bit 2 is in position 2 soStart at 2, check two positions, skip two positions, etc..2,3,6,7 are part of the pattern that P2 checks

    Position n7654321Whats ThereData Bit 4Data Bit 3Data Bit 2Parity Bit 3(P3)Data Bit 1Parity Bit 2(P2)Parity Bit 1(P1)

  • Hamming Code Check exampleI get sent a 7 bit binary word: 0101101Need to check that there is even parity for each of the three parity bit patternP1 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 soStart 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

    Position n7654321Word0101101P10011P20110P30101

  • Hamming Code Check example 2I get sent a 7 bit binary word: 0001101Need to check that there is even parity for each of the three parity bit patternP1 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 soStart at 4, check 4 skip 4(then we run out of bits) (4,5,6,7)

    xxP2 and P3 dont have Even Parity so this is NOT a correct pattern

    Position n7654321Word0001101P10011P20010P30001

  • QUIZ!!Have a go at the 4bit Hamming Checks quiz on Godalming Online before you move on!

  • 4 bit Creation Example - 1101Parity bit 1 is in position 1So 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 parityParity bit 2 is in position 2So 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 parityParity bit 3 is in position 4So 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 parityThe Final bit pattern sent is 1100110This includes the 4 data bits and three parity bitsStart by placing the 4 data bits in the correct positionsLeave spaces for the parity bits

    Positionn7654321Whats ThereData Bit 4Data Bit 3Data Bit 2Parity Bit 3(P3)Data Bit 1Parity Bit 2(P2)Parity Bit 1(P1)1101

    11010

    11011

    11001

    1100110

  • Why Bother?This seems A LOT of processing and redundant data just to validate a nibbleHamming Codes can FIX one bit of incorrect data!!!!!!!!!Hamming is an ERROR CORRECTION code

  • Remember this I get sent a 7 bit binary word: 0001101Need to check that there is even parity for each of the three parity bit patternP1 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 soStart at 4, check 4 skip 4(then we run out of bits) (4,5,6,7)

    xxP2 and P3 dont have Even Parity so this is NOT a correct pattern

    Position n7654321Word0001101P10011P20010P30001

  • Which bit is wrong??? Now add up the positions of the WRONG bitsP2 is position 2 and P3 is position 4 2+4 = 6Bit6 needs to be flipped from 0 to 1Check your self that this now is correctxx

    Position n7654321Word0001101P10011P20010P30001

  • NOWTry changing another data bi in the Patten and see if the hamming Have a go at the example in B&L