private uint ReadBits(int n) { uint total = 0; for (int i = 0; i < n; i++) { total += (uint)(ReadBit() << ((n - i)-1)); } return total; }