Advertisement
svetlozar_kirkov

Bits Exchange

Nov 29th, 2014
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.56 KB | None | 0 0
  1. using System;
  2.  
  3. namespace BitsExchange
  4. {
  5.     class BitsExchange
  6.     {
  7.         static void Main()
  8.         {
  9.             Console.Write("n = ");
  10.             UInt32 n = UInt32.Parse(Console.ReadLine());
  11.             Console.WriteLine("Before: {0}",Convert.ToString(n,2).PadLeft(32,'0'));
  12.             UInt32 small = n & (7 << 3);
  13.             UInt32 large = n & (7 << 24);
  14.             n = (n ^ (small | large)) | (large >> 21) | (small << 21);
  15.             Console.WriteLine("After: \t{0}\nResult: {1}",Convert.ToString(n,2).PadLeft(32,'0'),n);
  16.         }
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement