Example #1
0
        static void Test1()
        {
            DecodedMessage dm = new DecodedMessage("0100010000111101");
            //DecodedMessage dm = new DecodedMessage("0011111001001000");
            CodedMessage   cm      = new CodedMessage(dm);
            DecodedMessage dm_back = new DecodedMessage(cm);

            Console.WriteLine(dm);
            Console.WriteLine(cm);
            Console.WriteLine(dm_back);
            if (dm.ToString() == dm_back.ToString())
            {
                Console.WriteLine("All right!");
            }
            else
            {
                Console.WriteLine("Houston, we have a problem");
            }
        }
Example #2
0
        static void Test2()
        {
            DecodedMessage dm = new DecodedMessage("0");

            Console.WriteLine(dm);
            CodedMessage cm = new CodedMessage(dm);

            Console.WriteLine(cm);
            cm.MakeFault(0);
            Console.WriteLine(cm);
            DecodedMessage dm_back = new DecodedMessage(cm);

            Console.WriteLine(dm_back);
            if (dm.ToString() == dm_back.ToString())
            {
                Console.WriteLine("All right!");
            }
            else
            {
                Console.WriteLine("Houston, we have a problem");
            }
        }
Example #3
0
        public CodedMessage(DecodedMessage msg)
        {
            int len = msg.GetLength();

            for (int i = 1; i <= len; i++)
            {
                if (IsPowerOfTwo(i))
                {
                    len++;
                }
            }
            bits = new int[len];

            for (int i = 1, from = 0; i <= len; i++)
            {
                if (IsPowerOfTwo(i))
                {
                    bits[i - 1] = 0;
                }
                else
                {
                    bits[i - 1] = msg.GetBit(from++);
                    string bitStr = Convert.ToString(i, 2);
                    for (int k = 0; k < bitStr.Length; k++)
                    {
                        if (bitStr[k] == '0')
                        {
                            continue;
                        }
                        int power = bitStr.Length - k - 1;
                        int index = (int)Math.Pow(2, power) - 1;
                        bits[index] += bits[i - 1];
                        bits[index] %= 2;
                    }
                }
            }
        }