Example #1
0
        public static int[] square(int[] a, int aLen, int[] res)
        {
            long carry;

            for (int i = 0; i < aLen; i++)
            {
                carry = 0;
                for (int j = i + 1; j < aLen; j++)
                {
                    carry      = unsignedMultAddAdd(a[i], a[j], res[i + j], (int)carry);
                    res[i + j] = (int)carry;
                    carry      = (long)(((ulong)carry) >> 32);
                }
                res[i + aLen] = (int)carry;
            }

            BitLevel.shiftLeftOneBit(res, res, aLen << 1);

            carry = 0;
            for (int i = 0, index = 0; i < aLen; i++, index++)
            {
                carry      = unsignedMultAddAdd(a[i], a[i], res[index], (int)carry);
                res[index] = (int)carry;
                carry      = (long)(((ulong)carry) >> 32);
                index++;
                carry     += res[index] & 0xFFFFFFFFL;
                res[index] = (int)carry;
                carry      = (long)(((ulong)carry) >> 32);
            }
            return(res);
        }
Example #2
0
 internal BigInteger shiftLeftOneBit()
 {
     return((sign == 0) ? this : BitLevel.shiftLeftOneBit(this));
 }