public static int xFloorLog2(uint x) { x |= (x >> 1); x |= (x >> 2); x |= (x >> 4); x |= (x >> 8); x |= (x >> 16); return(Bithacks.Ones(x) - 1); }
public static int CeilingLog2(uint v) { int r = Bithacks.FloorLog2(v); if (r < 0) { return(r); } if (v != (uint)Bithacks.Power2((uint)r)) { return(r + 1); } else { return(r); } }