CSJ2K.j2k.util.MathUtil.log2 C# (CSharp) Méthode

log2() public static méthode

Method that calculates the floor of the log, base 2, of 'x'. The calculation is performed in integer arithmetic, therefore, it is exact.
public static log2 ( int x ) : int
x int The value to calculate log2 on. /// ///
Résultat int
        public static int log2(int x)
        {
            int y, v;
            // No log of 0 or negative
            if (x <= 0)
            {
                throw new System.ArgumentException("" + x + " <= 0");
            }
            // Calculate log2 (it's actually floor log2)
            v = x;
            y = - 1;
            while (v > 0)
            {
                v >>= 1;
                y++;
            }
            return y;
        }