Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Globalization;
- using System.Threading;
- public class BitFlipper
- {
- public static void Main()
- {
- Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
- checked
- {
- ulong number = ulong.Parse(Console.ReadLine());
- const ulong SEQ3BITS = 7;
- for (int position = 63; position >= 2; position--)
- {
- ulong bitMask = SEQ3BITS << (position - 2);
- ulong bitValue = (number & bitMask) >> (position - 2);
- if (bitValue == 0)
- {
- number |= bitMask;
- position -= 2;
- }
- else if (bitValue == SEQ3BITS)
- {
- number &= ~bitMask;
- position -= 2;
- }
- }
- Console.WriteLine(number);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement