You are on page 1of 15

Trng: HVKTQS Lp: Cao hc KHMT K23 Hc vin: Nguyn c Thy Nghin cu v Hamming v v d minh ha

M hamming Trong vin thng (telecommunication), m Hamming l mt m sa li tuyn tnh (linear errorcorrecting code), c t tn theo tn ca ngi pht minh ra n, Richard Hamming. M Hamming c th pht hin mt bit hoc hai bit b li (single and double-bit errors). M Hamming cn c th sa cc li do mt bit b sai gy ra. Ngc li vi m ca ng, m chn l (parity code) n gin va khng c kh nng pht hin cc li khi 2 bit cng mt lc b hon v (0 thnh 1 v ngc li), va khng th gip sa c cc li m n pht hin thy. Lch s Trong nhng nm ca thp nin k 1940, Hamming lm vic ti Bell Labs trn my tnh Bell Model V, mt my in c (electromechanical) dng r-le (relay-based), vi tc rt chm, my giy ng h mt chu k my. Nhp liu c cho vo my bng nhng ci th c l (punch cards), v hu nh my lun lun gy li trong khi c. Trong nhng ngy lm vic trong tun, nhng m c bit c dng tm ra li v mi khi tm c, n nhp nhy n bo hiu, bo cho ngi iu khin bit h sa, iu chnh my li. Trong thi gian ngoi gi lm vic hoc trong nhng ngy cui tun, khi ngi iu khin my khng c mt, mi khi c li xy ra, my tnh t ng b qua chng trnh ng chy v chuyn sang cng vic khc. Hamming thng lm vic trong nhng ngy cui tun v ng cng ngy cng tr nn bc tc mi khi ng phi khi ng li cc chng trnh ng dng t u, do cht lng km, khng ng tin cy (unreliability) ca b my c cc th c l. My nm tip theo , ng dn tm lc vo vic xy dng hng lot cc thut ton c hiu qu cao gii quyt vn sa li. Nm 1950, ng cng b mt phng php m hin nay c bit l M Hamming. Mt s chng trnh ng dng hin thi vn cn s dng m ny ca ng.

M hnh ca mt m 7-bit, bao gm 4 bit d liu (3,5,6,7) v 3 bit chn l (1,2,4). S lin quan ca cc bit d liu vi bit chn l c biu hin bng cc phn ca hnh trn gi ln nhau. Bit th 1 kim tra bit th (3, 5, 7), trong khi bit 2 kim tra bit (3, 6, 7). Lu , cc v tr (1,2,4 v.v.) thc ra l v tr 20, 21, 22 v.v.

Cc bit d liu v bit chn l trong mi quan h chng gi vi nhau. Cc bit chn l c tnh dng quy lut "s chn". Gi tr ca nhm d liu l 1100110 - cc bit chn l c in m, v c t phi sang tri. Cng nhiu bit sa li thm vo trong thng ip, v cc bit y c b tr theo mt cch l mi b tr ca nhm cc bit b li to nn mt hnh thi li ring bit, th chng ta c th xc nh c nhng bit b sai. Trong mt thng ip di 7-bit, chng ta c 7 kh nng mt bit c th b li, nh vy, ch cn 3 bit kim tra (23 = 8) l chng ta c th, khng nhng ch xc nh c l li trong truyn thng c xy ra hay khng, m cn c th xc nh c bit no l bit b li. Hamming nghin cu cc k hoch m ha hin c, bao gm c m hai-trong-nm, ri tng qut ha khi nim ca chng. Khi u, ng xy dng mt danh mc (nomenclature) din t h thng my, bao gm c s lng bit dng cho d liu v cc bit sa li trong mt khi. Chng hn, bit chn l phi thm 1 bit vo trong mi t d liu (data word). Hamming din t phng php ny l m (8,7). N c ngha l mt t d liu c tng s bit l 8 bit, trong ch c 7 bit l cc bit ca d liu m thi. Theo phng php suy ngh ny, m ti din (nhc li) trn phi c gi l m (3,1). T l thng tin l t l c tnh bng vic ly con s th hai chia cho con s th nht. Nh vy vi m ti din (3,1) trn, t l thng tin ca n l . Hamming cn pht hin ra vn vi vic o gi tr ca hai hoc hn hai bit na, v miu t n l "khong cch" (distance) (hin nay n c gi l khong cch Hamming (Hamming distance) theo ci tn ca ng). M chn l c khong cch bng 2, v nu c 2 bit b o ngc th li trong truyn thng tr nn v hnh, khng pht hin c. M ti din (3,1) c khong cch l 3, v 3 bit, trong cng mt b ba, phi b i ngc trc khi chng ta c mt t m khc. M ti din (4,1) (mi bit c nhc li 4 ln) c khong cch bng 4, nn nu 2 bit trong cng mt nhm b o ngc th li o ngc ny s i thot m khng b pht hin.
2

Cng mt lc, Hamming quan tm n hai vn ; tng khong cch v ng thi tng t l thng tin ln, cng nhiu cng tt. Trong nhng nm thuc nin k 1940, ng xy dng mt s k hoch m ha. Nhng k hoch ny u da trn nhng m hin tn ti song c nng cp v tin b mt cch su sc. B quyt cha kha cho tt c cc h thng ca ng l vic cho cc bit chn l gi ln nhau (overlap), sao cho chng c kh nng t kim tra ln nhau trong khi cng kim tra c d liu na. Thut ton cho vic s dng bit chn l trong `m Hamming`: Tt c cc bit v tr l cc s m ca 2 c dng lm bit chn l. (cc v tr nh 1, 2, 4, 8, 16, 32, 64 v.v. hay ni cch khc 20, 21, 22, 23, 24, 25, 26 v.v.) 1. Tt c cc v tr bit khc c dng cho d liu s c m ha. (cc v tr 3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, etc.) 2. Mi bit chn l tnh gi tr chn l cho mt s bit trong t m (code word). V tr ca bit chn l quyt nh chui cc bit m n lun phin kim tra v b qua (skips). o V tr 1 (n=1): b qua 0 bit(n-1), kim 1 bit(n), b qua 1 bit(n), kim 1 bit(n), b qua 1 bit(n), v.v. o V tr 2(n=2): b qua 1 bit(n-1), kim 2 bit(n), b qua 2 bit(n), kim 2 bit(n), b qua 2 bit(n), v.v. o V tr 4(n=4): b qua 3 bit(n-1), kim 4 bit(n), b qua 4 bit(n), kim 4 bit(n), b qua 4 bit(n), v.v. o V tr 8(n=8): b qua 7 bit(n-1), kim 8 bit(n), b qua 8 bit(n), kim 8 bit(n), b qua 8 bit(n), v.v. o V tr 16(n=16): b qua 15 bit(n-1), kim 16 bit(n), b qua 16 bit(n), kim 16 bit(n), b qua 16 bit(n), v.v. o V tr 32(n=32): b qua 31 bit(n-1), kim 32 bit(n), b qua 32 bit(n), kim 32 bit(n), b qua 32 bit(n), v.v. o v tip tc nh trn. Ni cch khc, bit chn l ti v tr 2k kim cc bit cc bit v tr t c gi tr logic ca php ton AND gia k v t l khc 0 V d dng (11,7) m Hamming Ly v d chng ta c mt t d liu di 7 bit vi gi tr l "0110101". chng minh phng php cc m Hamming c tnh ton v c s dng kim tra li, xin xem bng lit k di y. Ch d (data) c dng biu th cc bit d liu v ch p (parity) biu th cc bit chn l (parity bits). u tin, cc bit ca d liu c t vo v tr tng thch ca chng, sau cc bit chn l cho mi trng hp c tnh ton dng quy lut bit chn l s chn[1]. Th t bit 1 2 3 4 5 6 7 8 9 10 11

V tr bit chn l v cc bit d liu Nhm d liu (khng c bit chn l): p1 p2 p3 p4 Nhm d liu (vi bit chn l):

p1 p2 d1 p3 d2 d3 d4 p4 d5 d6 d7 0 1 0 0 0 1 1 0 1 0 1 0 0 1 1 0 0 1 0 1 1 0 0 0 1 1 0 0 1 0 1 1 0 1 1 1 0 1

Cch tnh cc bit chn l trong m Hamming (t tri sang phi) Nhm d liu mi (new data word) - bao gm cc bit chn l - by gi l "10001100101". Nu chng ta th cho rng bit cui cng b thoi ha (gets corrupted) v b ln ngc t 1 sang 0. Nhm d liu mi s l "10001100100"; Di y, chng ta s phn tch quy lut kin to m Hamming bng cch cho bit chn l gi tr 1 khi kt qu kim tra dng quy lut s chn b sai. Th t bit 1 2 3 4 5 6 7 8 9 10 11 V tr bit Bit chn l v Kim p1 p2 d1 p3 d2 d3 d4 p4 d5 d6 d7 chn cc bit d chn l l liu Nhm d liu nhn 1 0 0 0 1 1 0 0 1 0 0 1 c:

p1 p2 p3 p4

0 0 0

0 1 0

0 Sai 0 0 Sai

1 1

0 1 1 0

ng 0 0 1 0 0 Sai 1

Kim tra cc bit chn l (bit b o ln c nn thm) Bc cui cng l nh gi tr ca cc bit chn l (nn nh bit nm di cng c vit v bn phi - vit ngc li t di ln trn). Gi tr s nguyn ca cc bit chn l l 11 (10), v nh vy c ngha l bit th 11 trong nhm d liu (data word) - bao gm c cc bit chn l - l bit c gi tr khng ng, v bit ny cn phi i ngc li. p4 p3 p2 p1 Nh phn 1 0 1 1 Thp phn 8 2 1 = 11

Khi hai bit d liu (3,7) c cng bit chn l kim tra ti vi tr 2k - v d (1,2) - bin i gi tr (li trong truyn thng) th gi tr ca bit chn l vn ng nh gi tr gc (0,1) Vic i ngc gi tr ca bit th 11 lm cho nhm 10001100100 tr li thnh 10001100101. Bng vic b i phn m Hamming, chng ta ly c phn d liu gc vi gi tr l 0110101. Lu , cc bit chn l khng kim tra c ln nhau, nu ch mt bit chn l b sai thi, trong khi tt c cc bit khc l ng, th ch c bit chn l ni n l sai m thi v khng phi l cc bit n kim tra . Cui cng, gi s c hai bit bin i, ti v tr x v y. Nu x v y c cng mt bit ti v tr 2k trong i din nh phn ca chng, th bit chn l tng ng vi v tr y kim tra c hai bit, v do s gi nguyn gi tr, khng thay i. Song mt s bit chn l no y nht nh phi b thay i, v x y, v do hai bit tng ng no c gi tr x v y khc nhau. Do vy, m Hamming pht hin tt c cc li do hai bit b thay i song n khng phn bit c chng vi cc li do 1 bit b thay i. M Hamming (7,4) Hin thi, khi ni n m Hamming chng ta thc ra l mun ni n m (7,4) m Hamming cng b nm 1950. Vi mi nhm 4 bit d liu, m Hamming thm 3 bit kim tra. Thut ton (7,4) ca Hamming c th sa cha bt c mt bit li no, v pht hin tt c li ca 1 bit, v cc li ca 2 bit gy ra. iu ny c ngha l i vi tt c cc phng tin truyn thng khng c chm li t pht xy ra, m (7,4) ca Hamming rt c hiu qu (tr phi phng tin truyn thng c nhiu rt cao th n mi c th gy cho 2 bit trong s 7 bit truyn b o ln). V d v cch dng cc ma trn thng qua GF(2) Nguyn l ca m Hamming bt ngun t vic khai trin v m rng quan im chn l. Vic khai trin ny bt u bng vic nhn cc ma trn, c gi l Ma trn Hamming, vi nhau. i vi m Hamming (7,4), chng ta s dng hai m trn c lin quan gn gi, v t tn cho chng l:

v
6

Cc ct vect trong l nn tng hch ca v phn trn ca (4 hng u) l mt ma trn n v (identity matrix). Ma trn n v cho php vect d liu i qua trong khi lm tnh nhn, v nh vy, cc bit d liu s nm 4 v tr trn cng (sau khi nhn). Sau khi php nhn hon thnh, khc vi cch gii thch phn trc (cc bit chn l nm v tr 2k), trt t ca cc bit trong t m (codewords) y khc vi cch b tr ni (cc bit d liu nm trn, cc bit kim chn l nm di). Chng ta dng mt nhm 4 bit d liu (s 4 trong ci tn ca m l v vy) ch cht, v cng thm vo 3 bit d liu tha (v 4+3=7 nn mi c s 7 trong ci tn ca m). truyn gi d liu, chng ta hy nhm cc bit d liu m mnh mun gi thnh mt vect. Ly v d, nu d liu l "1011" th vect ca n l:

Gi s, chng ta mun truyn gi d liu trn. Chng ta tm tch ca mul 2 [3]:

v p, vi cc gi tr

My thu s nhn vi r, kim tra xem c li xy ra hay khng. Thi hnh tnh nhn ny, my thu c (mt ln na, cc gi tr ng d mul 2):

V chng ta c mt vect ton s khng cho nn my thu c th kt lun l khng c li xy ra


7

S d mt vect ton s khng c ngha l khng c li, bi v khi c nhn vi vect d liu, mt s thay i trong nn tng xy ra i vi khng gian bn trong vect (vector subspace), tc l hch ca . Nu khng c vn g xy ra trong khi truyn thng, r s nm nguyn trong hch ca v php nhn s cho kt qu mt vect ton s khng. Trong mt trng hp khc, nu chng ta gi s l li mt bit xy ra. Trong ton hc, chng ta c th vit:

mul 2, trong ei l vect n v ng th i , c ngha l, mt vect s 0 c mt gi tr 1 trong v tr i (tnh t 1 tnh i). Biu thc trn ni cho chng ta bit rng c mt bit b li ti v tr i. Nu by gi chng ta nhn vi c hai vect ny:

V r l d liu thu nhn c khng c li, cho nn tch ca

v r bng 0. Do

Vy, tch ca vi vect nn chun ti ct th i lm l ra ct trong , v th m chng ta bit rng li xy ra ti v tr ct ny trong . V chng ta kin to di mt hnh thc nht nh, cho nn chng ta c th hiu gi tr ca ct ny nh mt s nh phn - v d, (1,0,1) l mt ct trong , tng ng gi tr vi ct th 5, do chng ta bit li xy ra u v c th sa c n. Ly v d, gi s chng ta c:

Nu thi hnh php nhn:

Tch ca php nhn cho chng ta mt kt qu tng ng vi ct th 2 ("010" tng ng vi gi tr 2 trong s thp phn), v do , chng ta bit rng li xy ra v tr th 2 trong hng d liu, v v vy c th sa c li. Chng ta c th d dng thy rng, vic sa li do 1 bit b o ln gy ra, dng phng php trn l mt vic thc hin c. Bn cnh , m Hamming cn c th pht hin li do 1 bit hoc 2 bit b o ln gy ra, dng tch ca khi tch ny khng cho mt vect s khng. Tuy th, song m Hamming khng th hon thnh c hai vic. M Hamming v bit chn l b sung Nu chng ta b sung thm mt bit vo m Hamming, th m ny c th dng pht hin nhng li gy ra do 2 bit b li, v ng thi n khng cn tr vic sa cc li do mt bit gy ra. [1] Nu khng b sung mt bit vo thm, th m ny c th pht hin cc li do mt bit, hai bit, ba bit gy ra, song n s cn tr vic sa cc li do mt bit b o ln. Bit b sung l bit c p dng cho tt c cc bit sau khi tt c cc bit kim ca m Hamming c thm vo. Khi s dng tnh sa li ca m, nu li mt bit chn l b pht hin v m Hamming bo hiu l c li xy ra th chng ta c th sa li ny, song nu chng ta khng pht hin c li trong bit chn l, nhng m Hamming bo hiu l c li xy ra, th chng ta c th cho rng li ny l do 2 bit b i cng mt lc. Tuy chng ta pht hin c n, nhng khng th sa li c.

Ghi ch 1. 7 bit d liu 0000000 1010001 1101001 1111111 byte c bit chn l Quy lut s chn Quy lut s l 00000000 10100011 11010010 11111111 00000001 10100010 11010011 11111110
9

2. Cch tnh bit chn l trong nhm cc bit d liu, dng quy lut s chn nh sau: nu s

lng bit c gi tr bng 1 (the bit is set) l mt s l, th bit chn l bng 1 (v do vic cng thm mt bit c gi tr 1 ny vo d liu, tng s bit c gi tr 1 s l mt s chn bao gm c bit chn l, cn khng th bit chn l s c gi tr 0. Ngc li, bit chn l dng quy lut s l s c gi tr 1 nu s lng cc bit c gi tr bng 1 l mt s chn - do vic thm bit chn l c gi tr bng 1 vo nhm d liu, tng s bit c gi tr 1l mt s l - v bng 0 nu ngc li. 3. GF (nguyn ting Anh: Galois field - hay gi finite field), tm dch l "Trng Hu Hn". Xin xem thm bi ting Anh Finite field. 4. mul (nguyn ting Anh: Modulo) l php tnh s d trong tnh chia. V d 100/3 = 1 (c 33 d 1). Trong ton hc, nu c hai s nguyn a v b, cng mt s d n no , th biu thc a b (mod n) - ni l a v b c ng d munl n - c ngha l a v b c cng s d khi c chia cho n, hay ni mt cch tng t, a-b l mt bi s (multiple) ca n. Xin xem thm trong bi ting Anh Modulo Khong cch Hamming Trong l thuyt thng tin, Khong cch Hamming (ting Anh: Hamming distance) gia hai dy k t (strings) c chiu di bng nhau l s cc k hiu v tr tng ng c gi tr khc nhau. Ni mt cch khc, khong cch Hamming o s lng thay th cn phi c i gi tr ca mt dy k t sang mt dy k t khc, hay s lng li xy ra bin i mt dy k t sang mt dy k t khc. Ly v d:

Khong cch Hamming gia 1011101 v 1001001 l 2. Khong cch Hamming gia 2143896 v 2233796 l 3. Khong cch Hamming gia "toned" v "roses" l 3.

Trng lng Hamming (Hamming weight) ca mt dy k t l khong cch Hamming t mt dy k t ton s khng c cng chiu di. C ngha l s phn t trong dy k t khng c gi tr khng (0): i vi mt dy k t nh phn (binary string), n ch l s cc k t c gi tr mt (1), ly v d trng lng Hamming ca dy k t 11101 l 4. i vi mt chiu di c nh "n", khong cch Hamming l o trn khng gian vect ca cc t c chiu di , v n tha mn yu cu v tnh cht s khng m (non-negativity) (s tuyt i), hin thn ca tnh bt kh phn nh (indiscernibles) v tnh i xng (symmetry), v n c th c chng minh mt cch d dng bng php quy np ton phn (complete induction) rng n cn tha mn bt ng thc tam gic (triangle inequality) na. Khong cch Hamming gia hai t a v b cn c gi l trng lng Hamming (Hamming weight) ca php ton ab, dng mt ton t thch hp thay th cho ton t "". i vi hai dy k t nh phn a v b, php ton ny tng ng vi php ton a XOR b. Khong cch Hamming ca cc dy k t nh phn cn tng ng vi khong cch Manhattan
10

gia hai giao im ca mt hnh gi phng cp n (n-dimensional hypercube), trong n l chiu di ca cc t. Lch s v ng dng Khong cch Hamming l ci tn c t theo tn ca ng Richard Hamming, ngi gii thiu l thuyt ny trong ti liu c tnh c s ca ng v m pht hin li v sa li (error-detecting and error-correcting codes). N c s dng trong k thut vin thng tnh s lng cc bit trong mt t nh phn (binary word) b i ngc, nh mt hnh thc c tnh s li xy ra trong qu trnh truyn thng, v v th, i khi, n cn c gi l khong cch tn hiu (signal distance). Vic phn tch trng lng Hamming ca cc bit cn c s dng trong mt s ngnh, bao gm l thuyt tin hc, l thuyt m ha, v mt m hc. Tuy vy, khi so snh cc dy k t c chiu di khc nhau, hay cc dy k t c xu hng khng ch b thay th khng thi, m cn b nh hng bi d liu b lng thm vo, hoc b xa i, phng php o lng phc tp hn, nh khong cch Levenshtein (Levenshtein distance) l mt phng php c tc dng v thch hp hn. Chng trnh minh ha: code m ha v sa sai m hamming.
1. 2. 3. 4.
5. using using using using System; System.Collections.Generic; System.Text; System.Collections;

6. namespace Hamming
7. {

8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24.
25.

26. 27. 28. 29. 30.

class Hamming { public int WrongBit { get; private set; } public string EncodeString { get; private set; } public string DataString { get; private set; } /// <summary> /// Khoi tao chuoi hamming /// </summary> /// <param name="data">chuoi can xu ly</param> /// <param name="mode">true: endcode, false: decode</param> public Hamming(string data,bool mode) { WrongBit = 0; EncodeString = ""; DataString = ""; if (mode) { DataString = data; EncodeString = Encode(); } else { Decode(data);

11

31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41.
42.

43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60.
61.

62. 63. 64.


65. 66.

67. 68. 69. 70. 71. 72. 73. 74. 75.


76. 78. 79.

} } private string Encode() { string input = DataString; int r = 0; int _2r = 1; List<int> l = new List<int>(); l.Add(1); while (_2r <= input.Length + r + 1) { r++; _2r *= 2; l.Add(_2r); } byte[] a = new byte[_2r + 1]; bool[] ci = new bool[_2r + 1]; for (int i = 0; i < _2r + 1; i++) { ci[i] = false; a[i] = 0; } for (int i = 0; i < l.Count; i++) ci[l[i]] = true; int l_id = 0; int a_maxid = 0; for (int i = input.Length - 1, j = 1; i >= 0; j++) { if (j == l[l_id]) { l_id++; continue; } a[j] = (byte)Convert.ToInt16(input[i].ToString()); a_maxid = j; i--; } for (int i = 0; i < l.Count; i++) { int count = 0; int j = l[i]; while (j < _2r) { for (int k = 1; k <= l[i]; k++) { if (!ci[j] && a[j] == 1) count++; j++; } j += l[i];

77. 80. 81.

12

82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104.
105.

} if (count % 2 == 1) a[l[i]] = 1; else a[l[i]] = 0; } string result = ""; for (int i = a_maxid; i >= 1; i--) { result += a[i]; } return result; } private void Decode(string data) { byte[] a = new byte[data.Length + 1]; bool[] ci = new bool[data.Length+1]; for(int i=0;i<=data.Length;i++) { a[i]=0; ci[i]=false; } for(int i=data.Length-1,j=1;i>=0;i--) { a[j]=(byte)Convert.ToInt16(data[i].ToString()); j++; } int _2r = 1; List<int> l = new List<int>(); while(_2r<=data.Length) { l.Add(_2r); ci[_2r]=true; _2r *= 2; } for(int i=0;i<l.Count;i++) { int j = l[i]; int count = 0; while(j<=data.Length) { for(int k=1;k<=l[i]&j<=data.Length;k++) { if (!ci[j] && a[j] == 1) count++; j++; } j += l[i]; } if (count % 2 != a[l[i]]) WrongBit += l[i]; } if (WrongBit > data.Length) return;

106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123.
124. 125.

126. 127. 128. 129. 130. 131.

13

132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146.

a[WrongBit] = (byte)(a[WrongBit] == 1 ? 0 : 1); for (int i = data.Length; i >= 1; i--) { EncodeString += a[i].ToString(); if (!ci[i]) DataString += a[i].ToString(); } }

} class Program { static void Main(string[] args) { bool encode=true; string data=""; Console.WriteLine("Written by Kid <!-- s:D --><img src=\"{SMILIES_PATH}/4.gif\" alt=\":D\" title=\"ci ln\" /><!-- s:D -->"); 147. if (args.Length > 2 || args.Length == 0) 148. { 149. Console.WriteLine("Usage: Hamming <bit string> [option]"); 150. Console.WriteLine(" No option or -e: Encode"); 151. Console.WriteLine(" -d: Decode"); 152. } 153. else 154. { 155. for (int i = 0; i < args.Length; i++) 156. { 157. if (args[i][0] == '-') 158. switch (args[i][1]) 159. { 160. case 'd': 161. encode = false; 162. break; 163. case 'e': 164. break; 165. default: 166. Console.WriteLine("Unknown option!"); 167. return; 168. } 169. else 170. data = args[i]; 171. } 172. //encode = false; 173. //data = "100011101001110111010111110110101110"; 174. Hamming h = new Hamming(data, encode); 175. if (encode) 176. Console.WriteLine("Encode bit string: " + h.EncodeString); 177. else 178. {

14

179. 180. 181. 182. 183. 184. 185.


186. h.DataString); h.EncodeString); } } } } }

Console.WriteLine("Wrong bit: " + h.WrongBit); Console.WriteLine("Data bit string: " + Console.WriteLine("Fixed bit string:" +

15