projects
/
mono.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
510eae6
)
BigIngeter: new LeadingZeroCount helper method
author
theraot
<theraot@gmail.com>
Tue, 4 Mar 2014 16:12:41 +0000
(11:12 -0500)
committer
theraot
<theraot@gmail.com>
Tue, 4 Mar 2014 16:12:41 +0000
(11:12 -0500)
- The new helper method LeadingZeroCount returns the number of bits
that are set to 0 at the start of an uint.
mcs/class/System.Numerics/System.Numerics/BigInteger.cs
patch
|
blob
|
history
diff --git
a/mcs/class/System.Numerics/System.Numerics/BigInteger.cs
b/mcs/class/System.Numerics/System.Numerics/BigInteger.cs
index e52cd09431013fc55357897455ac1364f3f97bb0..be2289c4969f3b5a3c61a3e95770a1c9de71ec66 100644
(file)
--- a/
mcs/class/System.Numerics/System.Numerics/BigInteger.cs
+++ b/
mcs/class/System.Numerics/System.Numerics/BigInteger.cs
@@
-344,6
+344,16
@@
namespace System.Numerics {
return (int)(x & 0x0000003F);
}
+ static int LeadingZeroCount(uint value)
+ {
+ value |= value >> 1;
+ value |= value >> 2;
+ value |= value >> 4;
+ value |= value >> 8;
+ value |= value >> 16;
+ return 32 - PopulationCount (value); // 32 = bits in uint
+ }
+
public bool IsPowerOfTwo {
get {
bool foundBit = false;