Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class Program
- {
- static void Main()
- {
- Console.Write("Give me the number: ");
- uint number = uint.Parse(Console.ReadLine());
- string binaryRep = Convert.ToString(number, 2).PadLeft(32, '0');
- string threeToFive = binaryRep.Substring(26,3); // extract 3,4,5 bits
- string twentyFourToTwentySix = binaryRep.Substring(5, 3); // extract 24,25,26 bits
- // replacement operations
- string temp = twentyFourToTwentySix;
- string tempOne = binaryRep.Remove(5, 3);
- string tempTwo = tempOne.Insert(5, threeToFive);
- string tempThree = tempTwo.Remove(26, 3);
- string result = tempThree.Insert(26, temp); // result as binary number
- Console.WriteLine(result);
- uint finalNumber = Convert.ToUInt32(result, 2); // convert as Uint32.
- Console.WriteLine(finalNumber);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment