Created
October 26, 2016 18:57
-
-
Save nasko90/853918da92c77bf1d2bb97eaea5a9e80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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