Ejemplo n.º 1
0
        /// <summary>
        /// инициализирует таблицу для быстрого расчёта
        /// </summary>
        public void InitTable()
        {
            CRChelper <byte> charRefl = new CRChelper <byte>(Limits.CHAR_BIT, Reflect);
            CRChelper <T>    BitsRefl = new CRChelper <T>(Bits, Reflect);

            // factor-out constants to avoid recalculation
            T          fast_hi_bit = masking_type.HighBitMask;
            const byte byte_hi_bit = MaskUint <T> .ByteHighBitMask;

            // loop over every possible dividend value
            byte dividend = 0;

            do
            {
                T remainder = new T();

                // go through all the dividend's bits
                for (byte mask = byte_hi_bit; mask > 0; mask >>= 1)
                {
                    // check if divisor fits
                    if ((dividend & mask) != 0)
                    {
                        remainder = Operator <T> .Xor(remainder, fast_hi_bit);
                    }

                    // do polynominal division

                    bool bNotEqual = Operator <T> .NotEqual(Operator <T> .And(remainder, fast_hi_bit), Operator <T> .Zero);

                    if (bNotEqual)
                    {
                        remainder = Operator <T> .LeftShift(remainder, 1);

                        remainder = Operator <T> .Xor(remainder, TruncPoly);
                    }
                    else
                    {
                        remainder = Operator <T> .LeftShift(remainder, 1);
                    }
                }

                T tmp = BitsRefl.reflect(remainder);

                // следующее выражение необязательно. Просто можно обнулить старшие(неиспользуемые) биты в регистре
                //tmp = Operator<T>.And(tmp, masking_type.SigBits);

                Table_[charRefl.reflect(dividend)] = tmp;
                ++dividend;
            }while (dividend != 0);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Конструктор ЦРЦ-вычислителя
        /// </summary>
        public CRCoptimal(int Bits, T TruncPoly, T InitialRemainder, T FinalXorValue, bool ReflectInput = false, bool ReflectRemainder = false)
        {
            this.Bits             = Bits;
            this.ReflectInput     = ReflectInput;
            this.FinalXorValue    = FinalXorValue;
            this.ReflectRemainder = ReflectRemainder;
            this.TruncPoly        = TruncPoly;
            this.InitialRemainder = InitialRemainder;

            masking_type = new MaskUint <T>(Bits);
            helper_type  = new CRChelper <T>(Bits, ReflectInput);

            reflect_out_type = new CRChelper <T>(Bits, (ReflectRemainder != ReflectInput));

            Remainder = helper_type.reflect(InitialRemainder);

            crc_table_type = new CRCtable <T>(Bits, TruncPoly, ReflectInput);

            crc_table_type.InitTable();
        }