Advertisement
Guest User

Untitled

a guest
Jul 13th, 2015
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace WiggleWiggle
  8. {
  9.     class WiggleWiggle
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<long> input = Console.ReadLine().Split().Select(long.Parse).ToList<long>();
  14.             List<string> binary = new List<string>();
  15.             for (int i = 0; i < input.Count - 1; i+=2)
  16.             {
  17.                 char[] x = Convert.ToString(input[i], 2).PadLeft(63, '0').ToCharArray();
  18.                 char[] y = Convert.ToString(input[i + 1], 2).PadLeft(63, '0').ToCharArray();
  19.  
  20.                 SwitchBits(x, y);
  21.                 ReverseBits(x);
  22.                 ReverseBits(y);
  23.                 Console.WriteLine("{0} {1}", Convert.ToUInt64(String.Join("", x), 2), String.Join("", x));
  24.                 Console.WriteLine("{0} {1}", Convert.ToUInt64(String.Join("", y), 2), String.Join("", y));
  25.             }
  26.         }
  27.  
  28.         private static void ReverseBits(char[] x)
  29.         {
  30.             for (int h = 0; h < x.Length; h++)
  31.             {
  32.                 if (x[h] == '1')
  33.                 {
  34.                     x[h] = '0';
  35.                 }
  36.                 else if (x[h] == '0')
  37.                 {
  38.                     x[h] = '1';
  39.                 }
  40.             }
  41.         }
  42.  
  43.         private static void SwitchBits(char[] x, char[] y)
  44.         {
  45.             for (int j = x.Length - 1; j >= 0; j -= 2)
  46.             {
  47.                 x[j] ^= y[j];
  48.                 y[j] ^= x[j];
  49.                 x[j] ^= y[j];
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement