public static MInteger MayAddOneToLast(MInteger integer, bool addOneToLast) { if (addOneToLast) { return((new MInteger(integer)).AddOneToLast()); } return(new MInteger(integer)); }
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); }
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; } }
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); }
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))); }
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; } }
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); }
public MInteger(MInteger integer) { CreateBitList(); Append(integer); }