Didart

Binary Digits Count

Nov 3rd, 2021
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.42 KB | None | 0 0
  1. using System;
  2.  
  3. class Program {
  4.   public static void BinaryDigitsCount (string[] args) {
  5.  
  6.     int number = int.Parse(Console.ReadLine());
  7.     int binaryNumber = int.Parse(Console.ReadLine());
  8.  
  9.     int count = 0;
  10.     while(number != 0)
  11.     {
  12.       int leftover = number % 2;
  13.       if(leftover == binaryNumber)
  14.       {
  15.         count++;
  16.       }
  17.       number = number / 2;
  18.     }
  19.     Console.WriteLine (count);
  20.   }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment