Advertisement
ScorpS

Binary Digits Count

Dec 16th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1. using System;
  2.  
  3. class BinaryDigitsCount
  4. {
  5.     static void Main()
  6.     {
  7.         byte b = byte.Parse(Console.ReadLine());
  8.         int n = int.Parse(Console.ReadLine());
  9.         uint number = 0;
  10.         byte count = 0;
  11.  
  12.         for (int i = 1; i <= n; i++)
  13.         {
  14.             number = uint.Parse(Console.ReadLine());
  15.             while (number != 0)
  16.             {
  17.                 if (number % 2 == b)
  18.                 {
  19.                     count++;
  20.                 }
  21.                 number >>= 1;
  22.             }
  23.             Console.WriteLine(count);
  24.             count = 0;
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement