using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication1 {
static class Program {
public static void Main() {
var values = GetValues(50, 100);
foreach (var value in values) {
Console.WriteLine(
"Value: {0}\tBinary: {1}\tIsPowerOf2(): {2}",
value,
Convert.ToString(value, 2),
IsPowerOf2(value)
);
}
Console.WriteLine();
var result = Count2(values);
Console.WriteLine("Result: {0}", result);
}
static bool Count2(IEnumerable<int> values) {
return values.Count(IsPowerOf2) > 1;
}
static bool IsPowerOf2(int value) {
if (value <= 0) {
return false;
}
return (value & (value - 1)) == 0;
}
static int[] GetValues(int count, int max_value) {
var result = new int[count];
var random = new Random();
for (var i = 0; i < count; i++) {
result[i] = random.Next(max_value);
}
return result;
}
}
}
