Skip to content

Instantly share code, notes, and snippets.

@nasko90
Created October 26, 2016 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasko90/853918da92c77bf1d2bb97eaea5a9e80 to your computer and use it in GitHub Desktop.
Save nasko90/853918da92c77bf1d2bb97eaea5a9e80 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
namespace Operators
{
class Program
{
static void Main(string[] args)
{
int number = int.Parse(Console.ReadLine());
for (int i =3;i<6;i++)
{
int mask = 1 << i;
int wantedBit = (number & mask) >> i;
int mask2 = 1 << i + 21;
int otherBit = (number & mask2) >> i + 21;
if (wantedBit==1)
{
mask = 1 << i + 21;
number = number | mask;
}
else if (wantedBit == 0)
{
mask = ~(1 << i + 21);
number = number & mask;
}
if (otherBit == 1)
{
mask = 1 << i ;
number = number | mask;
}
else if (otherBit == 0)
{
mask = ~(1 << i );
number = number & mask;
}
}
Console.WriteLine(number);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment