Convert any decimal number into binary and then inverse it (Use of AND and NOT operators) :

static void Main(string[] args)
{
Console.Write(“Enter a number : “);
byte b = (byte) Int32.Parse(Console.ReadLine());
   for (int t = 128; t > 0; t = t / 2)
{
//Convent into binary
if ((b & t) != 0)
{
Console.Write(“1 “);
}
else
{
Console.Write(“0 “);
}

}
Console.WriteLine();

b = (byte) ~b;

for(int t=128;t>0;t=t/2)
{
//NOT operation
if((b&t)!=0)
{
Console.Write(“1 “);
}
else
{
Console.Write(“0 “);
}
}
Console.Read();
}


OUTPUT:
 
 
 

Leave a Reply