SHOW:
|
|
- or go back to the newest paste.
| 1 | using System; | |
| 2 | using System.Collections.Generic; | |
| 3 | ||
| 4 | class Program | |
| 5 | {
| |
| 6 | static void Main() | |
| 7 | {
| |
| 8 | Console.Write("Give me the number: ");
| |
| 9 | uint number = uint.Parse(Console.ReadLine()); | |
| 10 | ||
| 11 | string binaryRep = Convert.ToString(number, 2).PadLeft(32, '0'); | |
| 12 | ||
| 13 | string threeToFive = binaryRep.Substring(26,3); // extract 3,4,5 bits | |
| 14 | - | string twentySevenToTwentyNine = binaryRep.Substring(5, 3); // extract 24,25,26 bits |
| 14 | + | string twentyFourToTwentySix = binaryRep.Substring(5, 3); // extract 24,25,26 bits |
| 15 | ||
| 16 | // replacement operations | |
| 17 | - | string temp = twentySevenToTwentyNine; |
| 17 | + | string temp = twentyFourToTwentySix; |
| 18 | string tempOne = binaryRep.Remove(5, 3); | |
| 19 | string tempTwo = tempOne.Insert(5, threeToFive); | |
| 20 | string tempThree = tempTwo.Remove(26, 3); | |
| 21 | ||
| 22 | string result = tempThree.Insert(26, temp); // result as binary number | |
| 23 | Console.WriteLine(result); | |
| 24 | ||
| 25 | uint finalNumber = Convert.ToUInt32(result, 2); // convert as Uint32. | |
| 26 | ||
| 27 | Console.WriteLine(finalNumber); | |
| 28 | } | |
| 29 | } |