Maybe I'm just being stupid, but what is n? I don't see it defined anywhere.
Here's my code, documented and all [smile]:
/// <summary>/// Returns the highest set bit of <paramref name="value"/>, in the range of 0 to 31, and -1 if/// <paramref name="value"/> equals 0./// </summary>/// <param name="value">The value to find the highest set bit of.</param>/// <returns>/// The highest set bit of <paramref name="value"/>, in the range of 0 to 31, and -1 if/// <paramref name="value"/> equals 0.</returns>public static int HighestBitSet(System.Int32 value){ for (int i = 31; i >= 0; i--) if ((value & (1 << i)) != 0) return i; return -1;}
Hoping that helps...
EDIT: ah yes, you're doing it for a BigInt made from an array of values - I see clearly now!