Calculating The Hamming Code
Calculating The Hamming Code
ThekeytotheHammingCodeistheuseofextraparitybitstoallowtheidentificationofasingle
error.Createthecodewordasfollows:
1. Markallbitpositionsthatarepowersoftwoasparitybits.(positions1,2,4,8,16,32,64,etc.)
2. Allotherbitpositionsareforthedatatobeencoded.(positions3,5,6,7,9,10,11,12,13,14,
15,17,etc.)
3. Eachparitybitcalculatestheparityforsomeofthebitsinthecodeword.Thepositionofthe
paritybitdeterminesthesequenceofbitsthatitalternatelychecksandskips.
Position1:check1bit,skip1bit,check1bit,skip1bit,etc.(1,3,5,7,9,11,13,15,...)
Position2:check2bits,skip2bits,check2bits,skip2bits,etc.(2,3,6,7,10,11,14,15,...)
Position4:check4bits,skip4bits,check4bits,skip4bits,etc.
(4,5,6,7,12,13,14,15,20,21,22,23,...)
Position8:check8bits,skip8bits,check8bits,skip8bits,etc.(815,2431,4047,...)
Position16:check16bits,skip16bits,check16bits,skip16bits,etc.(1631,4863,8095,...)
Position32:check32bits,skip32bits,check32bits,skip32bits,etc.(3263,96127,160
191,...)
etc.
4. Setaparitybitto1ifthetotalnumberofonesinthepositionsitchecksisodd.Setaparitybit
to0ifthetotalnumberofonesinthepositionsitchecksiseven.
Hereisanexample:
Abyteofdata:10011010
Createthedataword,leavingspacesfortheparitybits:__1_001_1010
Calculatetheparityforeachparitybit(a?representsthebitpositionbeingset):
Position1checksbits1,3,5,7,9,11:
?_1_001_1010.Evenparitysosetposition1toa0:0_1_001_1010
Position2checksbits2,3,6,7,10,11:
0?1_001_1010.Oddparitysosetposition2toa1:011_001_1010
Position4checksbits4,5,6,7,12:
011?001_1010.Oddparitysosetposition4toa1:0111001_1010
Position8checksbits8,9,10,11,12:
0111001?1010.Evenparitysosetposition8toa0:011100101010
Codeword:011100101010.
Findingandfixingabadbit
Theaboveexamplecreatedacodewordof011100101010.Supposethewordthatwasreceivedwas
011100101110instead.Thenthereceivercouldcalculatewhichbitwaswrongandcorrectit.The
methodistoverifyeachcheckbit.Writedownalltheincorrectparitybits.Doingso,youwill
discoverthatparitybits2and8areincorrect.Itisnotanaccidentthat2+8=10,andthatbitposition
10isthelocationofthebadbit.Ingeneral,checkeachparitybit,andaddthepositionsthatarewrong,
thiswillgiveyouthelocationofthebadbit.
Tryoneyourself
Testifthesecodewordsarecorrect,assumingtheywerecreatedusinganevenparityHamming
Code.Ifoneisincorrect,indicatewhatthecorrectcodewordshouldhavebeen.Also,indicatewhat
theoriginaldatawas.
010101100011
111110001100
000010001010