ellapt

BinaryDigitsCount

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