svetlozar_kirkov

We All Love Bits

Oct 26th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2.  
  3. namespace WeAllLoveBits
  4. {
  5.     class WeAllLoveBits
  6.     {
  7.         static void Main()
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.             uint[] inputNums = new uint[n];
  11.             for (int i = 0; i < n; i++)
  12.             {
  13.                 inputNums[i] = uint.Parse(Console.ReadLine());
  14.             }
  15.             for (int i = 0; i < inputNums.Length; i++)
  16.             {
  17.                 string tempNumBinary = Convert.ToString(inputNums[i], 2);
  18.                 //
  19.                 string[] inverted = new string[tempNumBinary.Length];
  20.                 for (int j = 0; j < tempNumBinary.Length; j++)
  21.                 {
  22.                     if (tempNumBinary[j]=='0')
  23.                     {
  24.                         inverted[j] = "1";
  25.                     }
  26.                     else
  27.                     {
  28.                         inverted[j] = "0";
  29.                     }
  30.                 }
  31.                 int invertedInt = Convert.ToInt32(string.Join("", inverted),2);
  32.                 //
  33.                 string[] reversedArray = new string[tempNumBinary.Length];
  34.                 for (int k = tempNumBinary.Length-1, z=0; k >=0; k--,z++)
  35.                 {
  36.                     reversedArray[z] = tempNumBinary[k].ToString();
  37.                 }
  38.                 int reversed = Convert.ToInt32(string.Join("", reversedArray), 2);
  39.                 //
  40.                 long result = (inputNums[i] ^ invertedInt) & reversed;
  41.                 Console.WriteLine(result);
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment