Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class BitRoller
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int f = int.Parse(Console.ReadLine());
- int r = int.Parse(Console.ReadLine());
- int frozenBit = (n & (1 << f)) == 0 ? 0 : 1;
- for (int i = 0; i < r; i++)
- {
- if ((n & 1) != 0) //add bit @ pos 19 == to bit @ pos 0
- {
- n = n | (1 << 19);
- }
- int leftBit = (n & (1 << (f + 1))) == 0 ? 0 : 1; // the bit left from the frozenBit
- n = n & (~(1 << f)) | (leftBit << f); // exchange left bit and frozen bit
- n = n & (~(1 << (f+1))) | (frozenBit << (f+1));
- n = n >> 1; // removes right most bit
- }
- Console.WriteLine(n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement