public SingleBitTestResult SingleBitTest(string input) { foreach (var item in input) { if (item != '1' && item != '0') { throw new ArgumentException("Znaleziono zły znak: " + item); } } int Result = 0; Result = input.Count(c => c == '1'); SingleBitTestResult res = new SingleBitTestResult(); res.NumberOfOneBits = Result; if (Result > 9725 && Result < 10275) { res.TestPassed = true; } else { res.TestPassed = false; } return(res); }
public SingleBitTestResult SingleBitTest(byte[] input) { if (input.Length != bitsLength / 8) { throw new ArgumentException("Zła długość tablicy"); } int Result = 0; for (int i = 0; i < input.Length; i++) { int count = Convert.ToString(input[i], 2).ToCharArray().Count(c => c == '1'); Result += count; } SingleBitTestResult res = new SingleBitTestResult(); res.NumberOfOneBits = Result; if (Result > 9725 && Result < 10275) { res.TestPassed = true; } else { res.TestPassed = false; } return(res); }