X-Git-Url: https://git.novaco.in/?p=NovacoinLibrary.git;a=blobdiff_plain;f=Novacoin%2Fbase_uint.cs;h=e5a36bf9c1bbdb1371449bd31fc16ba7c6a08ad4;hp=83ef1edd101d95e5236794344f40c691357cd3d8;hb=584a6e678d645766a522fd5d25e5ae49726f7634;hpb=80b9c15a0c2d1b87180824a36948e37894cebaca diff --git a/Novacoin/base_uint.cs b/Novacoin/base_uint.cs index 83ef1ed..e5a36bf 100644 --- a/Novacoin/base_uint.cs +++ b/Novacoin/base_uint.cs @@ -62,6 +62,29 @@ namespace Novacoin } } + /// + /// Zero or the position of highest non-zero bit plus one. + /// + protected int bits + { + get + { + for (int pos = nWidth - 1; pos >= 0; pos--) + { + if (pn[pos]!=0) + { + for (int bits = 31; bits > 0; bits--) + { + if ((pn[pos] & 1 << bits)!=0) + return 32 * pos + bits + 1; + } + return 32 * pos + 1; + } + } + return 0; + } + } + public static bool operator !(base_uint a) { for (int i = 0; i < a.nWidth; i++)