public static int AlignSize(int sz, int n) { bool assert = ((n & (n - 1)) == 0); // n is a power of 2 if(!assert) throw new ArgumentException(); return (sz + n - 1) & -n; }