Esempio n. 1
0
        public void DivideStratis(uint Z)
        {
            arith256 div      = new arith256(pn);
            arith256 num      = new arith256(pn);
            ulong    quotient = 0;                 // the quotient.
            int      num_bits = num.pn.Length * 8;
            int      div_bits = div.pn.Length * 8; // Num of BITS

            if (div_bits == 0)
            {
                throw new Exception("Division by zero");
            }
            if (div_bits > num_bits)
            {
                return;                      // Answer == 0
            }
            int shift = num_bits - div_bits;

            div.LeftShift(shift); // shift so that div and num align.
            while (shift >= 0)
            {
                if (num.CompareTo(div) == 1 || num.CompareTo(div) == 0)
                {
                    num.Subtract(div.pn);
                    int originalvalue = (int)pn[shift / 32];
                    originalvalue |= ((int)1 << (int)(shift & 31)); // set a bit of the result.
                    pn[shift / 32] = (ulong)originalvalue;
                }
                div.RightShift(1); // shift back
                shift--;
            }
            // num now contains the remainder of the division.
            // return *this;
        }
Esempio n. 2
0
        public void Add(arith256 b)
        {
            ulong carry = 0;

            for (int i = 0; i < pn.Length; i++)
            {
                ulong n = carry + pn[i] + b.pn[i];
                pn[i] = n & 0xffffffff;
                carry = n >> 32;
            }
        }
Esempio n. 3
0
 public int CompareTo(arith256 b)
 {
     for (int i = pn.Length - 1; i >= 0; i--)
     {
         if (pn[i] < b.pn[i])
         {
             return(-1);
         }
         if (pn[i] > b.pn[i])
         {
             return(1);
         }
     }
     return(0);
 }