X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=Novacoin%2Fbase_uint.cs;h=a32fc6c409abc5a4513662f386cac58b590941d5;hb=HEAD;hp=502d871c01a506d94aa36d3fdd9b60dfa3d8df0f;hpb=0fe762d6eee8a8a23033f813217c1675a34f2d6a;p=NovacoinLibrary.git diff --git a/Novacoin/base_uint.cs b/Novacoin/base_uint.cs index 502d871..a32fc6c 100644 --- a/Novacoin/base_uint.cs +++ b/Novacoin/base_uint.cs @@ -28,31 +28,49 @@ namespace Novacoin /// public class base_uint : IComparable, IEquatable, IEqualityComparer { + #region Internal representation + /// + /// Length of internal representation + /// protected int nWidth; + /// + /// Big numbers are stored as array of unsigned 32-bit integers. + /// protected uint[] pn; + #endregion - public double getDouble() + #region Helper properties + public double Double { - double ret = 0.0; - double fact = 1.0; - - for (int i = 0; i < nWidth; i++) + get { - ret += fact * pn[i]; - fact *= 4294967296.0; - } + double ret = 0.0; + double fact = 1.0; + + for (int i = 0; i < nWidth; i++) + { + ret += fact * pn[i]; + fact *= 4294967296.0; + } - return ret; + return ret; + } } - public ulong GetLow64() + /// + /// First 64 bits as ulong value. + /// + public ulong Low64 { - return pn[0] | (ulong)pn[1] << 32; + get { return pn[0] | (ulong)pn[1] << 32; } } - public uint GetLow32() + /// + /// First 32 bits as uint value. + /// + public uint Low32 { - return pn[0]; + get { return pn[0]; } } /// @@ -69,17 +87,17 @@ namespace Novacoin /// /// Zero or the position of highest non-zero bit plus one. /// - protected int bits + public int bits { get { for (int pos = nWidth - 1; pos >= 0; pos--) { - if (pn[pos]!=0) + if (pn[pos] != 0) { for (int bits = 31; bits > 0; bits--) { - if ((pn[pos] & 1 << bits)!=0) + if ((pn[pos] & 1 << bits) != 0) return 32 * pos + bits + 1; } return 32 * pos + 1; @@ -88,7 +106,14 @@ namespace Novacoin return 0; } } + #endregion + + /// + /// Negation operator + /// + /// Value + /// True if value is zero, false otherwise. public static bool operator !(base_uint a) { for (int i = 0; i < a.nWidth; i++) @@ -219,7 +244,7 @@ namespace Novacoin } #endregion - #region Cast oerations + #region Cast operations /// /// True cast operator /// @@ -308,7 +333,7 @@ namespace Novacoin #region IEquatable public bool Equals(base_uint a) { - if (a == null) + if (object.ReferenceEquals(a, null)) { return false; }