Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _5.BitRoller
- {
- using System;
- public class BitRoller
- {
- public static void Main(string[] args)
- {
- checked
- {
- uint num = uint.Parse(Console.ReadLine());
- int frozenBit = int.Parse(Console.ReadLine());
- int timesR = int.Parse(Console.ReadLine());
- if (num != 0 && num != 524287)
- {
- string inputBinaryStr = Convert.ToString(num, 2);
- inputBinaryStr = inputBinaryStr.PadLeft(19, '0');
- int indexFrozenBit = 18 - frozenBit;
- string valueFrozenBit = inputBinaryStr[indexFrozenBit].ToString();
- string binNumStr = string.Empty;
- if (indexFrozenBit > 0)
- {
- binNumStr += inputBinaryStr.Substring(0, indexFrozenBit);
- }
- if (indexFrozenBit < 18)
- {
- binNumStr += inputBinaryStr.Substring(indexFrozenBit + 1);
- }
- for (int i = 0; i < timesR; i++)
- {
- binNumStr = binNumStr[17].ToString() + binNumStr.Remove(17);
- }
- string outputBinaryStr = binNumStr.Insert(indexFrozenBit, valueFrozenBit);
- uint ouputNum = Convert.ToUInt32(outputBinaryStr, 2);
- Console.WriteLine(ouputNum);
- }
- else
- {
- Console.WriteLine(num);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement