Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace BinaryDigitsCount
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- int number = int.Parse(Console.ReadLine());
- int binaryDigit = int.Parse(Console.ReadLine());
- int count = 0;
- while (number != 0)
- {
- int bitReminder = number % 2;// return only 1 or 0
- if (bitReminder == binaryDigit)
- {
- count++;
- }
- number = number / 2;// we divide by 2, because binary system base 2
- }
- Console.WriteLine(count);
- }
- }
- }
Add Comment
Please, Sign In to add comment