private void WrongCalculateButton_Click(object sender, EventArgs e) { if (WrongBitBox.Text == "") { MessageBox.Show("Wrong bit input!"); goto end; } HammingCodeRepresrnt hammingCodeRepresrnt = FillHammingCode(HammingCodeGlobal, WrongBitBox.Text); HammingCodeWrongBox.Text = hammingCodeRepresrnt.HammingCode; FindWrong(Convert.ToInt16(ControlBits.Text), Convert.ToInt16(InfoBits.Text), hammingCodeRepresrnt.HammingCode, controlBitsList); Decoding(HammingCodeGlobal); end: int k = 0; }
public HammingCodeRepresrnt FillHammingCode(string HammingCode, string WrongBit) { int WrongBitPosition = Convert.ToInt16(WrongBit); List <int> KontrolBitsPosition = new List <int> { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 }; HammingCodeRepresrnt hammingCodeRepresrnt = new HammingCodeRepresrnt(); hammingCodeRepresrnt.HammingCode = ""; hammingCodeRepresrnt.HammingCodePosition = new List <int>(); int x = 1; for (int i = 0; i < HammingCode.Length; i++) { if ((i + 1) == WrongBitPosition) { if (HammingCode[i] == '0') { hammingCodeRepresrnt.HammingCode += "1"; } else { hammingCodeRepresrnt.HammingCode += "0"; } hammingCodeRepresrnt.HammingCodePosition.Add(-1); continue; } if (KontrolBitsPosition.Contains(i + 1)) { hammingCodeRepresrnt.HammingCodePosition.Add(x); x = x * 2; } else { hammingCodeRepresrnt.HammingCodePosition.Add(0); } hammingCodeRepresrnt.HammingCode += HammingCode[i]; } return(hammingCodeRepresrnt); }