Exemple #1
0
/* reduces this DBIG mod a BIG, and returns the BIG */
    public virtual BIG mod(BIG c)
    {
        int k = 0;

        norm();
        DBIG m = new DBIG(c);

        if (comp(this, m) < 0)
        {
            return(new BIG(this));
        }

        do
        {
            m.shl(1);
            k++;
        } while (comp(this, m) >= 0);

        while (k > 0)
        {
            m.shr(1);
            if (comp(this, m) >= 0)
            {
                sub(m);
                norm();
            }
            k--;
        }
        return(new BIG(this));
    }
Exemple #2
0
/* reduces this DBIG mod a DBIG in place */

/*	public void mod(DBIG m)
 *      {
 *              int k=0;
 *              if (comp(this,m)<0) return;
 *
 *              do
 *              {
 *                      m.shl(1);
 *                      k++;
 *              }
 *              while (comp(this,m)>=0);
 *
 *              while (k>0)
 *              {
 *                      m.shr(1);
 *                      if (comp(this,m)>=0)
 *                      {
 *                              sub(m);
 *                              norm();
 *                      }
 *                      k--;
 *              }
 *              return;
 *
 *      }*/

/* return this/c */
    public virtual BIG div(BIG c)
    {
        int  k = 0;
        DBIG m = new DBIG(c);
        BIG  a = new BIG(0);
        BIG  e = new BIG(1);

        norm();

        while (comp(this, m) >= 0)
        {
            e.fshl(1);
            m.shl(1);
            k++;
        }

        while (k > 0)
        {
            m.shr(1);
            e.shr(1);
            if (comp(this, m) > 0)
            {
                a.add(e);
                a.norm();
                sub(m);
                norm();
            }
            k--;
        }
        return(a);
    }
Exemple #3
0
/* convert this to string */
    public override string ToString()
    {
        DBIG   b;
        string s   = "";
        int    len = nbits();

        if (len % 4 == 0)
        {
            len >>= 2;             //len/=4;
        }
        else
        {
            len >>= 2;
            len++;
        }

        for (int i = len - 1; i >= 0; i--)
        {
            b = new DBIG(this);
            b.shr(i * 4);
            s += (b.w[0] & 15).ToString("x");
        }
        return(s);
    }