Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _5.BitSifting_Bitwise
- {
- using System;
- public class BitSifting
- {
- public static void Main(string[] args)
- {
- checked
- {
- ulong initialBits = ulong.Parse(Console.ReadLine());
- int countSieves = int.Parse(Console.ReadLine());
- for (int i = 0; i < countSieves; i++)
- {
- ulong sieve = ulong.Parse(Console.ReadLine());
- initialBits = (initialBits ^ sieve) & initialBits;
- }
- // Console.WriteLine("Result num: " + initialBits);
- // Console.WriteLine("In Binary string: " + Convert.ToString((long)initialBits, 2));
- int bitCounter = 0;
- for (int bit = 0; bit < 64; bit++)
- {
- if ((initialBits & 1) > 0)
- {
- bitCounter++;
- }
- initialBits >>= 1;
- }
- Console.WriteLine(bitCounter);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement