Пример #1
0
 public static MInteger MayAddOneToLast(MInteger integer, bool addOneToLast)
 {
     if (addOneToLast)
     {
         return((new MInteger(integer)).AddOneToLast());
     }
     return(new MInteger(integer));
 }
Пример #2
0
        public static MInteger Add(MInteger firstInteger, MInteger secondInteger)
        {
            MInteger result  = new MInteger(firstInteger);
            MInteger counter = new MInteger();

            while (!counter.Equals(secondInteger))
            {
                result.Next();
                counter.Next();
            }
            return(result);
        }
Пример #3
0
        public byte GetByte(MInteger index)
        {
            if (IsNull())
            {
                return(0);
            }
            MCircularListNode <bool> node = list.firstNode;
            MInteger counter = new MInteger();
            bool     iterate = true;

            while (iterate)
            {
                if (counter.Equals(index))
                {
                    iterate = false;
                }
                else
                {
                    if (object.ReferenceEquals(node, list.lastNode))
                    {
                        return(0);
                    }
                    node = node.nextNode;
                }
            }
            MInteger limit = new MInteger("8");

            counter = new MInteger();
            byte result = 0;
            byte adder  = 1;

            while (true)
            {
                if (counter.Equals(index))
                {
                    return(result);
                }
                if (object.ReferenceEquals(node, list.lastNode))
                {
                    return(result);
                }
                if (node.nodeValue)
                {
                    result += adder;
                }
                adder *= 2;
                node   = node.nextNode;
            }
        }
Пример #4
0
        public MInteger RemoveFirst()
        {
            if (IsNull())
            {
                return(new MInteger());
            }
            if (list.firstNode == list.lastNode)
            {
                return(new MInteger());
            }
            MInteger result = new MInteger(this);

            result.list.lastNode  = list.lastNode;
            result.list.firstNode = list.firstNode.nextNode;
            return(result);
        }
Пример #5
0
 public static MInteger AddOptimized(MInteger firstInteger, MInteger secondInteger, bool carry)
 {
     if (firstInteger.IsNull() || secondInteger.IsNull())
     {
         if (firstInteger.IsNull())
         {
             return(MayAddOneToLast(secondInteger, carry));
         }
         else
         {
             return(MayAddOneToLast(firstInteger, carry));
         }
     }
     (bool resultCarry, bool bit) = AddBits(firstInteger.FirstBit(), secondInteger.FirstBit(), carry);
     return((new MInteger(bit)).Append(AddOptimized(firstInteger.RemoveFirst(), secondInteger.RemoveFirst(), resultCarry)));
 }
Пример #6
0
        public MInteger Append(MInteger integer)
        {
            if (integer.IsNull())
            {
                return(this);
            }
            MCircularListNode <bool> node = integer.list.firstNode;

            while (true)
            {
                Append(node.nodeValue);
                if (object.ReferenceEquals(node, integer.list.lastNode))
                {
                    return(this);
                }
                node = node.nextNode;
            }
        }
Пример #7
0
 public bool EqualsInteger(MInteger integer)
 {
     if (IsNull())
     {
         if (integer.IsNull())
         {
             return(true);
         }
         return(false);
     }
     if (integer.IsNull())
     {
         return(false);
     }
     if (FirstBit() == integer.FirstBit())
     {
         return(RemoveFirst().EqualsInteger(integer.RemoveFirst()));
     }
     return(false);
 }
Пример #8
0
 public MInteger(MInteger integer)
 {
     CreateBitList();
     Append(integer);
 }