Give a very good method to count the number of ones in a 32 bit number. (caution: looping through testing each bit is not a solution)
static void NumOfOnes(uint n) { int c = 0; for (int i=0; i<10; i++) { if ((n & (int)Math.Pow(2, i)) == (int)Math.Pow(2, i)) { c++; } } Console.WriteLine("{0}", c); }