private static int CountFromSide(byte[] bits, bool value, bool fromleft) { int counter = 0; var str = bits.ToBitStream(fromleft); foreach (var bit in str) { if (bit == value) ++counter; else return counter; } return counter; }