我从汉明代码网站上获取了代码。如果我想在12位消息和7位奇偶校验上实现它,我需要做哪些更改?我已经添加到DI [11]并且CI [6]位无法实现它的逻辑
string NrBinary;
long pp, Key=8, number;
double x, y;
Console.WriteLine("Give binary value till 12 bit: ");
NrBinary = Console.ReadLine();
if (NrBinary.Length <= 12)
{
if (NrBinary.Length == 1)
NrBinary = "000000000000" + NrBinary;
if (NrBinary.Length == 2)
NrBinary = "00000000000" + NrBinary;
if (NrBinary.Length == 3)
NrBinary = "0000000000" + NrBinary;
if (NrBinary.Length == 4)
NrBinary = "000000000" + NrBinary;
if (NrBinary.Length == 5)
NrBinary = "00000000" + NrBinary;
if (NrBinary.Length == 6)
NrBinary = "0000000" + NrBinary;
if (NrBinary.Length == 7)
NrBinary = "000000" + NrBinary;
if (NrBinary.Length == 8)
NrBinary = "00000" + NrBinary;
if (NrBinary.Length == 9)
NrBinary = "0000" + NrBinary;
if (NrBinary.Length == 10)
NrBinary = "000" + NrBinary;
if (NrBinary.Length == 11)
NrBinary = "00" + NrBinary;
if (NrBinary.Length == 12)
NrBinary = "0" + NrBinary;
pp = NrBinary.Length;
number = Convert.ToInt64(NrBinary);
Console.WriteLine("PP = " + pp);
for (Key = 0; Key < pp; ++Key)
{
x = Math.Pow(2, Key) - 1;
y = pp + Key;
if (x >= y)
{
goto Mess;
}
}
Mess:
Console.WriteLine("Controlled bit needed Key = " + Key + "\n");
long[] parity = new long[pp];
long[] DI = new long[pp];
long[] CI = new long[Key];
DI[0] = number % 10;
DI[1] = (number / 10) % 10;
DI[2] = (number / 100) % 10;
DI[3] = (number / 1000) % 10;
DI[4] = (number / 10000) % 10;
DI[5] = (number / 100000) % 10;
DI[6] = (number / 1000000) % 10;
DI[7] = (number / 10000000) % 10;
DI[8] = (number / 100000000) % 10;
DI[9] = (number / 1000000000) % 10;
DI[10] = (number / 10000000000) % 10;
DI[11] = (number / 100000000000) % 10;
CI[0] = DI[11] ^ DI[0] ^ DI[1];
CI[1] = DI[1] ^ DI[2] ^ DI[3];
CI[2] = DI[3] ^ DI[4] ^ DI[5];
CI[4] = DI[5] ^ DI[6] ^ DI[7];
CI[5] = DI[7] ^ DI[8] ^ Convert.ToInt64(DI[9]);
CI[6] = CI[1] ^ CI[2] ^ CI[3] ^ CI[4] ^ CI[5] ^ CI[6];
Console.WriteLine("\n = " + CI[0] + "" + CI[1] + "" + CI[2] + "" + CI[3] + "" + CI[4] + "" + CI[5] + "" + CI[6] + "\n");
Console.Write("Bit with Hamming code: ");
Console.WriteLine(DI[11] + "" + DI[10] + "" + DI[9] + "" + DI[8] + "" + DI[7] + "" + DI[6] + "" + DI[5] + "" + DI[4] + "" + DI[3]
+ "" + DI[2] + "" + DI[1] + "" + DI[0] + "" + CI[6] + "" + CI[5] + "" + CI[4] + "" + CI[3] + "" + CI[2] + "" + CI[1] + "" + CI[0]);
/*Console.WriteLine(DI[7] + "" + DI[6] + "" + DI[5] + "" + DI[4] + "" + CI[3] + "" + DI[3]
+ "" + DI[2] + "" + DI[1] + "" + CI[2] + "" + DI[0] + "" + CI[1] + "" + CI[0]);*/
}
else
{
Console.WriteLine("\n\n 8 bit character maximally:)");
}
Console.ReadKey();
}