sharp-biginteger/IntBase.cs

52 lines
892 B
C#

using System;
using System.CodeDom;
using System.Dynamic;
using sharp.extensions;
namespace BigInt
{
public abstract class IntBase
{
protected UInt32[] rawValue;
public UInt32[] RawValue
{
get { return this.rawValue; }
protected set
{
this.rawValue = value;
}
}
public byte[] getBytes()
{
byte[] b = new byte[this.RawValue.Length << 2];
for (int n = 0; n < this.RawValue.Length; n++)
{
b.Insert(this.RawValue[n].GetBytes(), n << 2);
}
return b;
}
public bool this[int bit]
{
get { return ((this.RawValue[bit >> 5] & (1 << (bit & 0x1F))) != 0); }
}
public bool isZero(){
return BigIntMath.isZero(rawValue);
}
public string toHexString()
{
return getBytes().Reverse().toHexString();
}
public override string ToString()
{
return String.Format("[{0}: {1}]",this.GetType().Name,toHexString());
}
}
}