Home > DeveloperSection > Blogs > Basic Concept and program for Bit-Wise Operation

Basic Concept and program for Bit-Wise Operation


C# C# 
Ratings:
0 Comment(s)
 130  View(s)
Rate this:

Basic Concept and program for Bit-Wise Operation

Today's world is a digital world. All the computerized data manipulation is done in binary format because it is directly implemented in digital electronic circuitry using logic gates. The binary system is used internally by almost all modern computers and computer-based devices.

For C#, below is the bit-wise operators which are used to manipulate the data:

  Operator         Description  

        &             Binary AND Operator

        |             Binary OR Operator 

        ^            Binary XOR Operator

        ~            Binary Ones Complement Operator       

        <<         Binary Left Shift Operator

        >>         Binary Right Shift Operator

 

Here is the complete code to implement these operators:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace ConsoleApplication5

{

    class Program

    {

        static void Main(string[] args)

        {

            int a, b, c, d;

            Console.Write("Enter the First Number : ");

            a = Convert.ToInt32(Console.ReadLine());

            Console.Write("Enter the Second Number : ");

            b    = Convert.ToInt32(Console.ReadLine());

            c = a& b; 

            Console.WriteLine("Result for the AND operator is {0}", c);

            c = a | b;

            Console.WriteLine("Result for the OR operator  is {0}", c);

            c = a ^ b;

            Console.WriteLine("Result for the XOR operator is {0}", c);

            c = ~a;

            d = ~b;

            Console.WriteLine("Result for the Binary Ones Complement Operator of 1st number is {0} and for 2nd is {1}", c,d);

            c = a << 2;

            d = b<< 2;

            Console.WriteLine("Result for the Binary Left Shift Operaton of 1st number is {0} and for 2nd is {1}", c,d);

            c = a>> 2;

            d = b>> 2;

            Console.WriteLine("Result for the Binary Right Shift Operator of 1st number is {0} and for 2nd is {1}", c,d);

            Console.ReadLine();

        }

    }

}



 

 


Don't want to miss updates? Please click the below button!

Follow MindStick