public StaticBitArray And(StaticBitArray value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } if (value.Length != Length) { throw new ArgumentException(nameof(value)); } for (int i = 0; i < arr.Length; i++) { arr[i] &= value.arr[i]; } return(this); }
public static void TestStaticBitArray() { const int length = 250; StaticBitArray bits = new StaticBitArray(length); bool[] checkAr = new bool[length]; Console.WriteLine(bits + " " + bits.Length); Console.WriteLine(checkAr + " " + checkAr.Length); for (int i = 0; i < length; i++) { bool val = (Rand.Next(2) == 1); checkAr[i] = val; bits[i] = val; } for (int i = 0; i < length; i++) { Debug.Assert(checkAr[i] == bits[i], $"FAIL, index = {i}"); } Console.WriteLine("[] OK"); int n = 0; foreach (bool bit in bits) { Debug.Assert(checkAr[n++] == bit, $"FAIL, index = {n}"); } Console.WriteLine("foreach OK"); bits.Not(); for (int i = 0; i < length; i++) { Debug.Assert(checkAr[i] != bits[i], $"FAIL, index = {i}"); } }
public Enumerator(StaticBitArray obj) { this.obj = obj; }