Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- /*Обръщане на няколко поредни (еднакви) бита се прави с маска*/
- class ChangeBits
- {
- static void Main()
- {
- ulong N = ulong.Parse(Console.ReadLine());
- //int bits = 62;
- int bits = 61;
- while(bits >= 0)
- {
- //bits--;
- ulong last3Bits = (N >> bits) & 7;//буташ ги и ги сравняваш със 111
- if(last3Bits == 0 || last3Bits == 7)
- {
- N ^= ((ulong)7 << bits);
- bits -= 2;
- }
- bits--;
- }
- Console.WriteLine(N);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment