public static uint MostSignificantBitSet( uint value ) { uint result = 0; while ( value != 0 ) { ++result; value >>= 1; } return result - 1; }